[英]How to create a onedrive file downloader in c#
I try to build an app store but I have a problem with my downloader I try to create a file downloader but it's not working at all !!! 我尝试建立一个应用程序商店,但我的下载器有问题,我尝试创建文件下载器,但它根本无法正常工作! And my visual still tell me that my app doesn't have any errors on codes !
而且我的视觉效果仍然告诉我,我的应用程序在代码上没有任何错误! O think that the problem with the direct link from OneDrive !
O认为直接来自OneDrive的问题! Plz help me the code is :
请帮我的代码是:
[C#] [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!");
}
I guess your url is wrong. 我猜你的网址是错误的。 If you share a link to your file it looks like:
如果您共享文件链接,则它看起来像:
https://onedrive.live.com/ redir ?resid=698A32FCADE8DFDA%2121825
https://onedrive.live.com/ redir ?resid = 698A32FCADE8DFDA%2121825
You have to replace the redir
by download
and it will download the file to your storage location: 您必须通过
download
替换redir
,它将文件下载到您的存储位置:
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);
As an alternative you can simply open this link in your browser and the file will be automatically downloaded to your download directory: 或者,您只需在浏览器中打开此链接,该文件就会自动下载到您的下载目录中:
Process.Start("https://onedrive.live.com/download?resid=698A32FCADE8DFDA%2121825");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.