Tuesday, July 21, 2009

Sending document in a document library as a mail attachment

SharePoint dcument library contains "Email as a link" item in the individual items context menu that -from its name-enables you to send the link of the document using the outlook express email,



One day i asked to make a feature that can send the document itself as an attachment inside email with.

I thougt that i can make a new context menu item in the doucment library that redirect you to a page in which you can wirte your email and send the mail via smtp containing the original docuemt as an attachment,

The main issue in this idea is how to know the source docuemt in the mail page, with some crawling behind the query string of similar functionality i found that sharepoint pages uses some javascript variables that read the id of the source and the source url (to go back after sending mail.) etc..,

Now do the following steps to do so:




  1. Click Site Actions Menu the Edit Page


  2. Add Web Part choose "Content Editor Web Part".


  3. Open properties pane in the source editor cope and paste the following code inside script tag:


    function Custom_AddDocLibMenuItems(m, ctx)
    {
    var strDisplayText = ""; var strAction = ""; var strImagePath = "";
    strDisplayText = "Send Document To People";
    strAction = "window.location= '" + ctx.HttpRoot + "/_layouts/SndItmPpl.aspx?ID="+currentItemID+"&Source="+ GetSource()+"&list="+ctx.listName+"'";
    // Add our new menu item
    CAMOpt(m, strDisplayText, strAction, strImagePath);
    // add a separator to the menu
    CAMSep(m);
    // false means that the standard menu items should also be rendered
    return false;
    }
  4. From Layout property check "Hidden".
  5. the appove code add "Send Document To People" menu item to the docuemt library which open the page SndItmPpl.aspx passing source url, Item Id, parent list name to it in the query string.


  6. now copy and paste the attached SndItmPpl.aspx to your "Template" folder in the following path in your server "\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS".
  7. You can find the aspx file Here

  8. This page like the "Gmail compose mail" page but it will contain the original document by defualt.


thanks

3 comments:

  1. Thanks, mate. It's always charming to see helpful FAQ's for newbies like us being posted for non profit thoughts. Have a good one!

    ReplyDelete
  2. Wow - you really putting lots of effort in writing this post - the screen pic. are wonderful very helpful - THNX!

    ReplyDelete