I need to download a file which is in SharePoint online programmatically. The link I have is in this format:


All the posts I can find refer to editing the URL from guestaccess.aspx to download.aspx, but that doesn't work for a URL in this format.

I'm trying to download the file in an AutoIT script, which will be available to a lot of users.

The link allows the file to be downloaded, but only by clicking the download button in Excel Online after the file is opened in a browser.

Is there any way I can do this? Amending the URL? Creating a different type of link in SharePoint? Or using any API?

  • Have you tried string path = "https://xxxxx.sharepoint.com/:f:/g/EkcBNxpXTKZJrg3xdBWlFBEBlgVj4FInALm_JVs4kYfK8w?e=tPfJVv"; string downloadUrl = siteURl + "/_layouts/download.aspx?SourceUrl=" + path; Commented Nov 5, 2018 at 5:04

3 Answers 3


Thanks for the response Lee_MSFT. I couldn't get your suggestion to work, but I got an answer on another forum.

I replaced everything after the last '?' with 'download=1'. Then the link can be used in my code to pull the file down.

Thanks for your help.

  • Worked for me yesterday
    – Lee Meador
    Commented Nov 15, 2019 at 15:40

When you request the anonymous link, user will be redirect to a URL with sourcedoc parameter, then you could download the file by download.aspx with UnqiueId parameter.




I have used 'download=1' to direct download a public file in SharePoint. It is working fine but this is working for .docx, .xlsx & .zip files only, it is not working for images & .txt file. So i have used following option & it is working for all files.

Public URL: https://xxxxx.sharepoint.com/:f:/g/EkcBNxpXTKZJrg3xdBWlFBEBlgVj4FInALm_JVs4kYfK8w?e=tPfJVv

you need to get file Unique id from this URL i.e. EkcBNxpXTKZJrg3xdBWlFBEBlgVj4FInALm_JVs4kYfK8w

and update URL to:


You will also need to update the name of the Sharepoint site in the URL above (here: "Developer") to match the site your file is located in.


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.