gpt4 book ai didi

c# - 如何在 C# 中创建一个 onedrive 文件下载器

转载 作者:太空宇宙 更新时间:2023-11-03 21:13:24 25 4
gpt4 key购买 nike

我尝试建立一个应用程序商店,但我的下载器有问题 我尝试创建一个文件下载器,但它根本不起作用!!!而且我的视觉效果仍然告诉我我的应用程序没有任何代码错误!O认为来自OneDrive的直接链接有问题!请帮助我,代码是:

[C#]

private void btnDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri(url.Text), path.Text ; )

private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}

private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}

最佳答案

我猜你的网址是错误的。如果您共享指向您的文件的链接,它看起来像:

https://onedrive.live.com/redir?resid=698A32FCADE8DFDA%2121825

您必须将 redir 替换为 download ,它会将文件下载到您的存储位置:

string path = @"your storage location";
string source = "https://onedrive.live.com/download?resid=698A32FCADE8DFDA%2121825";//right download url
//string source = "https://onedrive.live.com/redir?resid=698A32FCADE8DFDA%2121825";//wrong download url

WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;
webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
webClient.DownloadFileAsync(new Uri(source), path);

或者,您只需在浏览器中打开此链接,文件就会自动下载到您的下载目录:

Process.Start("https://onedrive.live.com/download?resid=698A32FCADE8DFDA%2121825");  

关于c# - 如何在 C# 中创建一个 onedrive 文件下载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36140846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com