1

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) {
            alert(L_EditDocumentRuntimeError_Text);
            window.onfocus = RefreshOnNextFocus;
        }
        else if (errorCode == 2)
            alert(L_EditDocumentProgIDError_Text);
    }

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 – Atish Dipongkor - MVP Nov 5 '15 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. – Kaushal15 Nov 5 '15 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 – Atish Dipongkor - MVP Nov 5 '15 at 12:50
  • yes exactly.... – Kaushal15 Nov 5 '15 at 12:53
  • Do you have document URL already? – Atish Dipongkor - MVP Nov 5 '15 at 13:00
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.

Example

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 :) – Kaushal15 Nov 6 '15 at 6:17
  • I am not able to open the .msg file in outlook using web=1 parameter. Any idea on that? – users1100 Jul 27 '18 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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