Ale*_*xGH 2 c# asp.net dropbox-api
我正在尝试下载 Dropbox 中的 pdf 文件,我需要将其保存到本地计算机(例如任何文件夹)中C:\Users\User\Desktop。这是我一直在使用的代码:
public void DownloadPdf()
{
DropboxClient client2 = new DropboxClient("cU5M-asdgfsdfsdfds3434435dfgfgvXoAMCFyOXH");
string folder = "MyFolder";
string file = "Test PDF.pdf";
var response = client2.Files.DownloadAsync("/" + folder + "/" + file);
}
Run Code Online (Sandbox Code Playgroud)
如何将该文件保存到本地驱动器中?接下来我需要做什么?它不会抛出任何错误,但我什至不确定路径是否会进入 Dropbox 中的 pdf 文档。我在 ASP.net Core 中使用 Dropbox.Api。
您需要做的是将内容转换为流并下载到本地路径。你可以这样做
public void DownloadPdf(string localFilePath)
{
DropboxClient client2 = new DropboxClient("cU5M-asdgfsdfsdfds3434435dfgfgvXoAMCFyOXH");
string folder = "MyFolder";
string file = "Test PDF.pdf";
using (var response = await client.Files.DownloadAsync("/" + folder + "/" + file))
{
using (var fileStream = File.Create(localFilePath))
{
(await response.GetContentAsStreamAsync()).CopyTo(fileStream);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10032 次 |
| 最近记录: |