I need to Open/Download Word or PowerPoint Document directly from Provider Hosted SharePoint App. We can perform easily in on-premise using editDocumentWithProgID2

Tried with getting CORE.js, SP.js and other related js files from 15 hive and placed in solution with referencing inside the aspx page.

<script src="../Scripts/js/SP.Init.js"></script>
<script src="../Scripts/js/SP.Core.js"></script>
<script src="../Scripts/js/SP.Runtime.js"></script>
<script src="../Scripts/js/SP.js"></script>    
<script src="../Scripts/js/CORE.JS"></script>    

This below function is called on anchor tag in javascript.

function EditDocumentFile(filename) {                        
        editDocumentWithProgID2(filename, '', 'SharePoint.OpenDocuments', '0', '/', '0');

function editDocumentWithProgID2(strDocument, varProgID, varEditor, bCheckout, strhttpRoot, strCheckouttolocal) {            

        var sURL = unescape(window.location.pathname);
        window.location.href = sURL;           

        var errorCode = editDocumentWithProgIDNoUI(strDocument, varProgID, varEditor, bCheckout, strhttpRoot, strCheckouttolocal);            

        if (errorCode == 1) {
            window.onfocus = RefreshOnNextFocus;
        else if (errorCode == 2)

Not working and shows error:

Uncaught ReferenceError: unescapeProperly is not defined

in browser developer tool console.

Any idea how to work with editDocumentWithProgID2 in CSOM ?

  • Can you check this out stackoverflow.com/a/1842937/1294606 Commented Nov 5, 2015 at 6:41
  • Thanx Atish, Yes I already have done this way. The reference which you gave would work only for on-premise. Let me edit my question again.
    – Kb15
    Commented Nov 5, 2015 at 12:06
  • is your requirement only to open/download document whenever users will click on the link? if so, then I have a alternative solution for you Commented Nov 5, 2015 at 12:50
  • yes exactly....
    – Kb15
    Commented Nov 5, 2015 at 12:53
  • Do you have document URL already? Commented Nov 5, 2015 at 13:00

1 Answer 1


Based on the comment, I am writing an alternative solution.

Add ?web=1 or ?web=0 for open or download your document.

  • web=0 means file will be downloaded when you hit this URL in browser.
  • web=1 means file will be opened in browser using office online.


Let's say your document URL is serverurl/Local Library/SharePoint 2013 Installation Guide.docx, Now create the <a> like following for opening this document

<a href="serverurl/Local Library/SharePoint 2013 Installation Guide.docx?web=1">file Name</a>

For downloading

<a href="serverurl/Local Library/SharePoint 2013 Installation Guide.docx?web=0">file Name</a>
  • Yes I thought of that..and using this now !! Thanks atish :)
    – Kb15
    Commented Nov 6, 2015 at 6:17
  • I am not able to open the .msg file in outlook using web=1 parameter. Any idea on that?
    – users1100
    Commented Jul 27, 2018 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.