locked
Open document directly from lookup column in view, in the client application RRS feed

  • Question

  • I have the script below (taken from the link below) in a script editor web part on a view of a list in SharePoint Online. What I am trying to do is open the document directly from this link in the client application to save the user from having to open the document's properties, then have the document open in Word/Excel Online, then open it up in the client application. The script has the problem that when clicking on the link, it is prompting me to save the file - that is not what I want. I want the file to open in the client application (on the destination library being looked up, the default experience is set to "open in client applicaiton".

    Does anyone know how I can adapt the script below to overcome that problem?

    https://sharepoint.stackexchange.com/questions/181068/how-to-setup-a-lookup-column-refering-to-a-document-librarys-file-url

    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", CSR_Setup);
    
    function CSR_Setup() {
        var overridectx = {};
        overridectx.Templates = {};
        overridectx.Templates.Fields = {
            "Document": { "View": CSR_AddLinkToFile }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overridectx);
    }
    
    function CSR_AddLinkToFile(ctx) {
        return String.format("<a href='{0}'>Link</a>", ctx.CurrentItem.FileRef, ctx.CurrentItem.FileLeafRef);
    }

    Tuesday, June 26, 2018 9:16 AM

All replies

  • Hi,

    You can try something like below. It may help you.

    function CSR_AddLinkToFile(ctx) {
        return String.format("<a href='{0}?web=1'>Link</a>", ctx.CurrentItem.FileRef, ctx.CurrentItem.FileLeafRef);
    }

    Please mark it as an answer if it helps.

    Regards.

    Tuesday, June 26, 2018 9:59 AM
  • Hi,

    Add the following code into script editor web part in the list view page.

    <script type="text/javascript">
    (function () {	 
       var overridectx = {};
        overridectx.Templates = {};
        overridectx.Templates.Fields = {
            "Document": { "View": CSR_AddLinkToFile }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overridectx);
    })();
     
    function CSR_AddLinkToFile(ctx) {
    	var siteUrl=_spPageContextInfo.webAbsoluteUrl;
    	var docUrl=ctx.CurrentItem.FileRef;
    	return "<a href='javascript:void(0)' onclick='editDocumentWithProgID2(\""+docUrl+"\",\"\",\"SharePoint.OpenDocuments\", \"0\",\""+siteUrl+"\", \"0\")'>Link</a>";
    }
    </script>

    More information:

    https://consultantpoint.wordpress.com/2014/10/14/calling-a-function-from-sp-js-open-word-document-directly-using-client-application/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, June 27, 2018 3:49 AM
  • Hi,

    Would you please provide us with an update on the status of your issue?

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, July 5, 2018 8:14 AM
  • Thanks Dennis,

    I used your code in the script editor, but upon testing a popup appeared saying "This site says... We're sorry, we couldn't find a program to open this document".

    I do have Office 2016 installed.

    Thursday, July 5, 2018 2:24 PM
  • Hi,

    Did you use the IE to access SharePoint site?

    If you click the "link" in folder item in the list view, you will receive this error, please check it.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, July 6, 2018 9:56 AM
  • Hi Dennis,

    I'm using Edge to access the SharePoint site.

    The same error occurs in Chrome.

    How can I get around this error?

    Monday, July 9, 2018 8:41 AM
  • Hi,

    Please try to use IE to check if it works.

    In Chrome, using F12 to check the JavaScript errors.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Monday, July 9, 2018 9:54 AM