Open Document directly in Edit Mode within SharePoint from an Email link

If you send a link to a SharePoint document with Email to another user, the document is opened in read only mode. It is not possible to open it directly in Edit Mode.

Therefore I wrote a little JavaScript which can do that easily.

Steps to implement:

1.) Create a new page on the sitecollection you want to have this ability. Name it OpenDoc.
2.) Add the "XML-Viewer" WebPart from "Content Rollup" category.
3.) Open the WebPart Settings of the XML-Viewer WebPart
4.) Click on XML-Editor Button and add following JavaScript into it:

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(LoadDoc, "sp.js");

function LoadDoc() {
  JSRequest.EnsureSetup(); 
  var file = JSRequest.QueryString["file"];
  if (typeof file != "undefined" && file != "") {    
    var baseUrl= "http://sharepoint/sites/mysite";     
    var host = location.protocol + "//" + location.host;    
    var docUrl = file.replace(host, "");
    var i = file.lastIndexOf("/");
    var listUrl = file.substr(0, i);
    editDocumentWithProgID2(docUrl, '', 'SharePoint.OpenDocuments', '0', baseUrl, '0')
    location.href = listUrl;
  }

}
</script>

5.) Adapt the baseUrl variable to your sitecollection

That's it.


When you want to open a file directly in edit mode copy the link of the file :


To open the file in edit mode you have to create the link manually. DocumentUrl is the copied file url.


  • PageUrl + ? + file= + DocumentUrl


like


  • http://sharepoint/sites/mysite/sitepages/opendoc.aspx?file=http://sharepoint/sites/mysite/docs/lavazza.xls



Comments

Simon said…
Awesome! Thanks for this. Works a charm in our Sharepoint 2013 environment. I was having problems putting a link to an Excel file in the Quick Launch bar. This script fixed it. Thanks for sharing.

Popular posts from this blog

Open SharePoint 2010/2013 Display, Edit, New Forms in Modal Dialogs

Ways to redirect http requests in SharePoint

How to create a FAQ in SharePoint with OOB features