How to generate directly download link from the shared OneDrive link

Anonymous
2024-08-08T05:12:32+00:00

Dear Experts and Supporters

I'm a developer working on an issue related to downloading files from OneDrive.

Everything was running fine until a few days ago when I reopened my app

Here is my lines

// shared OneDrive link example

// https://1drv.ms/u/s!Atj71Lw5QEdsrQnTRHMj-fjGc49N?e=hOB5gO

if (string.IsNullOrWhiteSpace(sharingURL))

    return string.Empty;

var base64Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(sharingURL));

var encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/', '_').Replace('+', '-');

var directlyUrl = $"https://api.onedrive.com/v1.0/shares/{encodedUrl}/root/content";

And now when I cannot download from OneDrive, I have debugged and realized that there was a 401 Unauthorized exception

But the file has been shared for Everyone with Edit permissions.

I thought Microsoft has changed something about the shared link recently and the current way to get the directly download link as it is now is not possible.

The shared link I see it's longer than before and different in format (no s!, no ?e=)

So please kindly help me to solve this case.

Thanks in advance!

Henry Tien (ti*********@outlook.com)

Microsoft 365 and Office | Install, redeem, activate | For home | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2024-08-08T12:22:17+00:00

Dear Nguyễn Quyết Tiến,

Welcome to Microsoft Community.

We understand that you need to set up a code to help you generate a download link from a shared link.

According to your description, you have previously used the code to generate a download link from OneDrive's shared link and used it, but now an error occurs.

OneDrive can share file or folder information with others and edit or save files together, but when generating a link, it is a shared link. If you need to generate a download link at the same time, you need to use the code to help you confirm it together.

Problems with OneDrive code that require more technical information to help you solve them are covered in a dedicated section in Microsoft learn (English only). Experts there may know more about how to solve your problem.

It is designed to support advanced users like you. Many users prefer to ask questions and get more professional responses through this section.

Here is a link to a forum where you can raise specific issues and share your ideas for solving the problem.

Microsoft 365 - Microsoft Q&A

OneDrive - Microsoft Q&A

Finally, although I can't help you further, I hope the information I provide can help you find a better direction.

I will keep this issue on file in case our great volunteers come up with ideas for you.

Best regards

Zenobia.Z | Microsoft Community Support Specialist

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-08-09T05:45:08+00:00

    Dear Nguyễn Quyết Tiến,

    Thank you for your understanding. As OneDrive is constantly updating, the code you set previously may not be detected and run in the new connection.

    You can try to post your question in Microsoft Learn, where more professionals will help you confirm the problem and check your code information.

    Hope you can get help in other sections. If you have other questions later, you can also reply to us.

    Best regards

    Zenobia.Z | Microsoft Community Support Specialist

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-08-08T14:00:09+00:00

    Dear Zenobia.Z - MSFT,

    Thank you very much for your support and your information.

    I understand and I'll share this issue on the links you mentioned here.

    Microsoft 365 - Microsoft Q&A

    OneDrive - Microsoft Q&A

    OneDrive can share file or folder information with others and edit or save files together, but when generating a link, it is a shared link. If you need to generate a download link at the same time, you need to use the code to help you confirm it together.

    ⇒ Yes, exactly we need to write some source code to convert a shared link to a direct download link. And I have also referenced it in one of your documents below link:

    https://learn.microsoft.com/en-us/graph/api/shares-get?view=graph-rest-1.0&tabs=csharp#encoding-sharing-urls

    note: in this link, maybe the source code is for SharePoint files because it used Microsoft.Graph APIs.

    The source code I shared above is the solution that I consulted from many sources, and importantly, I have been using it since 2021 until now without any problems.

    Anyway, thank you very much.

    Once again, wishing you health and luck.

    Best regards,

    Henry Tien (t**********@outlook.com)

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-08-08T07:15:55+00:00

    I have also tried with the original shared link without converting it to base64 and the result is still the same.

    add: although the share link I see has the suffix ?e= but the result is also the same

    Was this answer helpful?

    0 comments No comments