Forum Discussion

tienit's avatar
tienit
Copper Contributor
Aug 08, 2024

How to generate a direct download link from the shared OneDrive link

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 are 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 had changed something about the shared link recently and the current way to get the direct 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 (email address removed for privacy reasons)

Resources