The SharePoint products and technologies are very powerful and usable tools although some areas could use some improvement. Some of my clients have asked for the functionality to mail documents as attachments and mail URLs using Outlook 2003. This simple productivity feature helps boost user productivity and demonstrates SharePoint integration capabilities with Office.
 
Overview
The functionality is created by modifying the OWS.JS which contains code for rendering the menu and the menu functions. The function we’ll modify is “function AddDocLibMenuItems(m, ctx)” located around line 10298 – this code renders the menu for the document library. In addition, we’ll add the “function mailDocument(documentUrl)” and “function mailDocumentUrl(documentUrl)” functions.
 
Modifying the AddDocLibMenuItems function
  • The code required for the mail document functions is as follows:
    Backup your OWS.JS.
  • Find the line containing “function AddDocLibMenuItems(m, ctx)”.
  • Just beneath the following code:

strDisplayText = L_EditProperties_Text;   
strAction = "STSNavigate(‘" + ctx.editFormUrl+"?ID="+ currentItemID +
"&Source=" + GetSource() + RootFolder + "’)";
strImagePath = ctx.imagesPath + "edititem.gif";
CAMOpt(m, strDisplayText, strAction, strImagePath);

  • Add the following code:

//new function to add mail document to doc lib libraries
//
//
    strDisplayText = "Mail Document";
    strAction = "mailDocument(‘" + currentItemFileUrl + "’)";
    strImagePath = ctx.imagesPath + "mapi16.gif";
    CAMOpt(m, strDisplayText, strAction, strImagePath);
//
//
//new function to add mail document to doc lib libraries

//new function to add mail document to doc lib libraries
//
//
    strDisplayText = "Mail Url";
    strAction = "mailDocumentUrl(‘" + currentItemFileUrl + "’)";
    strImagePath = ctx.imagesPath + "mapi16.gif";
    CAMOpt(m, strDisplayText, strAction, strImagePath);
//
//
//new function to add mail document to doc lib libraries

Adding the maildocument and maildocumentUrl functions

  • Go to the GetRootFolder function around line 10376.
  • Browse to end of function and add the following code:

//new function to add mail document to doc lib libraries
//added August 24 2005 by Ron Charity
//
function mailDocument(documentUrl)   
    {
  try{
   var protocolParts = location.href.split("//");
   var urlParts = protocolParts[1].split("/");
   var fileUrl = "http://" + urlParts[0] + documentUrl;
   
   var outlook = new ActiveXObject("Outlook.Application");
   var outlookMessage = outlook.CreateItem(0);
   outlookAttachment = outlookMessage.Attachments.Add(fileUrl);
   outlookMessage.Display();
      
   CollectGarbage();
  }
  catch(e){
   alert("This functionality requires Microsoft Office Outlook 2003 to be installed on your PC.");
  }
}
//
//
//end of new function

//new function to add mail document url to doc lib libraries
//added August 24 2005 by Ron Charity
//
function mailDocumentUrl(documentUrl)
    {
  try{
   var protocolParts = location.href.split("//");
   var urlParts = protocolParts[1].split("/");
   var fileUrl = "http://" + urlParts[0] + documentUrl;
   
   var outlook = new ActiveXObject("Outlook.Application");
   var outlookMessage = outlook.CreateItem(0);
   outlookMessage.Subject = "Document URL";
   outlookMessage.Body = "Link to document:" + "n" + fileUrl;
   outlookMessage.Display();
      
   CollectGarbage();
  }
  catch(e){
   alert("This functionality requires Microsoft Office Outlook 2003 to be installed on your PC.");
  }
}
//
//
//end of new function

  • Save the code.
  • Run IIS Reset.
  • Open Outlook.
  • Open IE and browse to a Document Library and test the functions.
  • Done.

These added features provide greater functionality which helps boost user productivity and are simple to implement. Use caution though in multiplatform environments such as Mac – the code uses ActiveX.

 

Advertisements