1

I have a SharePoint document library. Currently, when I select a document , click on "Copy Link" and share the link to users, when user clicks on link, document opens either in Office web apps or Client application depending on library settings. (Copy Link is with setting "Anyone with access can view the document")

Instead, is it possible, to restrict opening this so that when user clicks the link, it directly gets downloaded?

  • this works in Chrome, but not IE... any thoughts? – user85578 Jul 24 at 21:01
1

Append following URL before your document copy link URL. It will allow users to only download the document.

http://sharepointSiteURL/_layouts/download.aspx?SourceUrl=http://DocumentCopyLinkUrl

You can either do it manually or do customization in your view to have such URL.

Update:

Try following customization using CSR for generating downloadable link.
Try it out, if it works in SharePoint-Online.
If it doesn't work try modifying URL as answered by @Anthony Wang MSFT

  1. In your document library, create a column (Single Line of Text) with name say "DownloadLink".
  2. Create a js file and put following CSR code and Save it (e.g. in Site Assets with name as DownloadLinkScript.js)

    (function () {
        function registerRenderer() {
            var ctxObj = {};
            ctxObj.Templates = {};    
            ctxObj.Templates = {
                Fields : {
                    'DownloadLink': {
                        View : function (ctx) {
                            var siteUrl = _spPageContextInfo.webAbsoluteUrl;
                            var url = String.format('{0}/_layouts/download.aspx?SourceUrl={1}', siteUrl, (siteUrl + ctx.CurrentItem.FileRef));
                            return String.format('<a href="{0}">{1}</a>', url, ctx.CurrentItem.FileLeafRef);
                        }
                    },
                }
            };
            SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxObj);
        }
        ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');
    })();
    
  3. Go to your document library view --> Edit Page --> Edit Web Part --> Miscellaneous --> JS Link. Add following URL in it and Click on OK and Save the page.

    ~siteCollection/SiteAssets/DownloadLinkScript.js
    
  4. Reload the page and you will notice there is a hyperlink in "Download Link" column with file name.

  • Manually will be bit tricky as there are multiple users sharing links and not all of them are having SharePoint Developer/Administrator background. They are basically content managers. Any suggestions for customization methods as how it can be done please? – 404 Apr 16 '18 at 6:09
  • Also unfortunately the above link does not work for me. It throws error. – 404 Apr 16 '18 at 6:22
  • Update: The above link does not work with url generated from "Copy URL" command. If I manually append end to end path like SharePoint Site/DocumentLibrary/FolderName/DocumentName.Extension, then it would work. But again, non-sharepoint users will find it difficult to do so. – 404 Apr 16 '18 at 6:29
0

You can manually create below URL for directly download document using URL.

https://{SiteURL}/{library internalName}/{documentName}
https://console.sharepoint.com/sites/TestSite/BulkTestDocLib/document.docx

if Documents inside folder then use below URL

https://{SiteURL}/{library internalName}/{folder DisplayName}/{documentName}
https://console.sharepoint.com/sites/TestSite/BulkTestDocLib/folder1/document.docx https://console.sharepoint.com/sites/TestSite/BulkTestDocLib/folder1/folder2/document.docx

Note: -

  • This Link not work after document rename or folder rename
  • This is only work for those user who have view/read permission
0

When you copy the link , it will look like https://xxx.sharepoint.com/personal/username/_layouts/15/guestaccess.aspx?guestaccesstoken=ayx%3d&docid=xyz&rev=1

You have to do is replace the guestacces.aspx with download.aspx . It will look like :

https://xxx.sharepoint.com/personal/xyz/_layouts/15/download.aspx?guestaccesstoken=xyz%3d&docid=xyz&rev=1
0

I usually download the document. Use Ctrl+J to go to Download section copy the URL from there and share the URL with whoever wants to download the document.

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.