How the add document link sharing via email functionality

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned


Share link via email

Sense/Net's built-in sharing functionality allows you to share content (Post, Document, etc) between workspaces or portal users through the workspace- and user walls. But sometimes you do not have to share the content itself but the content's path via email. This tutorial is provided to show how to accomplish this functionality in Sense/Net with developing a custom javascript based action.


1. Create a custom ShareViaEmail action

Copy the built-in ShareAction and name it for example to ShareViaEmailAction. Change the dialog in the code from SN.Wall.openShareDialog to SN.Wall.openShareViaEmailDialog.

Remaining part of the action developement will be finished in javascript. Build the project and if it’s necessary copy the modified dll-s to the production environment’s bin folder.

public override string MethodName
                return "SN.Wall.openShareViaEmailDialog";
                base.MethodName = value;

2. Add your custom Action to the portal

To use your custom action you have to create an Application content in the Content Repository.

  • Navigate to /Root/(apps)/GenericContent int he content explorer’s tree and add a new Application.
  • Add a DisplayName (this will be shown in action lists and menus).
  • Add the list of the chosen scenarios (if you want to display them in listitem action menus, add ListItem scenario). With the Icon identifier field you can define the icon which will be shown in the action link (e.g. upload a 16x16px image to the /Root/Global/images/icons/16 folder with a name shareviaemail and add this icon name as Icon identifier).
  • Put the action’s name into the Action type name field.
Add new share Application

3. Add the JavaScript part

Add sharing via email functionality to /Root/Global/scripts/sn/SN.Wall.js (this is the file where the built-in sharing related scripts are stored)

  • Copy and paste the following code (config part) into /Root/Global/scripts/sn/SN.Wall.js to row 40.
shareViaEmailDialogConf: {
        title: SN.Resources.Picker["ShareViaEmail"],
        modal: true,
        zIndex: 10000,
        width: 400,
        height: 'auto',
        minHeight: 0,
        maxHeight: 350,
        minWidth: 400,
        resizable: false,
        autoOpen: true,
        close: function () { $(this).dialog("destroy") }

  • Copy and paste the following code to row 348.
openShareViaEmailDialog: function (contentId) {
       var dialogId = 'sn-sharecontent-' + contentId;
$('body').append('<div id="' + dialogId + '" class="sn-sharecontent"></div>');
       var el = $('#' + dialogId);
        $(el).load('/Root/Global/renderers/Wall/ShareViaEmail.aspx?contentid=' + contentId + '&rnd=' + Math.random(), function () {
SN.Util.CreateUIDialog($(this), SN.Wall.shareViaEmailDialogConf);
shareViaEmail: function (contentId, path, title, user) {
        var $sharediv = $('#sn-sharecontent-' + contentId);
        var postId = $('.sn-postid', $sharediv).val();
        var email = $sharediv.find('#emailAddress').val();
        var $sharetext = $('.sn-share-text', $sharediv);
        var text = $sharetext.val();
        if (text == SN.Wall.shareDefaultText)
            text = ''; 
var body = text + '%0D%0A' + title + '%0D%0A' + encodeURIComponent(document.location.origin + path);
window.location = 'mailto:' + email + '?subject=' + user + 'shared a document with you: ' + title + '&body=' + body;

As you can see this code will load an aspx file where we can define the html of the share dialog.

  • So the next step is to navigate to /Root/Global/renderers/Wall folder and create a copy from the Share.aspx. Rename it to ShareViaEmail.aspx.

  • Copy and paste the following code into the newly created aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="SenseNet.ContentRepository.Storage" %>
<%@ Import Namespace="SenseNet.ContentRepository.Workspaces" %>
<%@ Import Namespace="SenseNet.Portal.Helpers" %>
<%@ Import Namespace="SenseNet.ContentRepository" %>
<%@ Import Namespace="SenseNet.Portal.UI" %>
    var contentId = Request["contentid"]; 
    var id = Convert.ToInt32(contentId);
    var currentUser = SenseNet.ContentRepository.User.Current as SenseNet.ContentRepository.User;
    var currentUserFullName = currentUser.FullName;  
    var contextNode = Node.LoadNode(id);
    var contextGc = contextNode as GenericContent;
    var sharedisplayname = HttpUtility.HtmlEncode(contextGc.DisplayName);
    var sharecontenttype = contextGc.NodeType.Name;
    var sharepath = contextGc.Path;
<div class="sn-sharecontent-maindiv">
    <input class="sn-postid" type="hidden" value="<%= contentId %>" />
  <div class="sn-sharecontent-emaildiv">
    <input type="text" placeHolder="email address" id="emailAddress"style="margin: 10px;width: 366px;padding: 5px;" />
    <div class="sn-sharecontent-postboxdiv">
        <textarea class="sn-unfocused-postbox sn-share-text" onfocus="SN.Wall.onfocusPostBox($(this), true);" onblur="SN.Wall.onblurPostBox($(this), true);"><%=GetGlobalResourceObject("WallRenderers", "WriteSomething")%></textarea>
    <div class="sn-sharecontent-contentcarddiv">
	    <div class="sn-sharecontent-contentcarddiv-right">
		    <strong><%=sharedisplayname %></strong>&nbsp;(<%=sharecontenttype%>)
		    <div class="sn-wrap"><small><%=sharepath%></small></div>
	    <div class="sn-wall-clear">
<div class="sn-sharecontent-buttoncontainer">
    <div class="sn-sharecontent-buttondiv">
        <input type="button" class="sn-submit sn-button sn-notdisabled sn-sharebutton" 
value="<%=GetGlobalResourceObject("WallRenderers", "Share")%>" 
onclick="SN.Wall.shareViaEmail('<%= contentId %>','<%= sharepath %>','<%= sharedisplayname %>','<%= currentUserFullName %>    ');return false;" />
        <input type="button" class="sn-submit sn-button sn-notdisabled sn-closeshare" value="<%=GetGlobalResourceObject("WallRenderers", "Close")%>" onclick="SN.Wall.closeShareDialog('<%= contentId %>');return false;" />

  • Now you can check sharing functionality for example on a document in a document library


Sharing via email

Sharing via email

Be sure that the user will be able to reach and download the shared file only in those cases when she has the permission to open it.

Related links


There are no external references for this article.