简体   繁体   中英

Get shared link to a file Dropbox API v2.0 c#

I'm using Dropbox.Net API v2.0 to upload document to Dropbox:

private async Task Upload(DropboxClient dbx, string localPath, string remotePath)
    {
        using (var fileStream = File.Open(localPath, FileMode.Open))
        {
            var s = await dbx.Files.UploadAsync(remotePath, body: fileStream);
        }
    }

How do I get a shared link to the uploaded document?

I have tried that:

await dbx.Sharing.GetSharedLinkFileAsync(remotePath);

But got the following error:

<Message>An error has occurred.</Message>
<ExceptionMessage>shared_link_not_found/.</ExceptionMessage>

I'm nissing something but not sure what, any idea?

I found the answer:

var result = await  dbx.Sharing.CreateSharedLinkWithSettingsAsync(remotePath);
var url = result.Url;

That worked perfectly.

var link = dbx.Sharing.ListSharedLinksAsync(FolderName + "/" + UploadFileName);
if (link.Result.Links.Count == 0)
{
 var result = 
        dbx.Sharing.CreateSharedLinkWithSettingsAsync(FolderName+"/"+UploadFileName);
 string url = result.Result.Url;
}
 else
{
 string url = link.Result.Links[0].Url;
 URL = url;
}

This way you can check existing links and add new if required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM