如何在c#中创建onedrive文件下载器(How to create a onedrive file downloader in c#)

编程入门 行业动态 更新时间:2024-10-28 14:33:06
如何在c#中创建onedrive文件下载器(How to create a onedrive file downloader in c#)

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

[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 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 ! Plz help me the code is :

[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

您必须通过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);

作为替代方案,您只需在浏览器中打开此链接,该文件将自动下载到您的下载目录:

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

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

You have to replace the redir by download and it will download the file to your storage location:

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");

更多推荐

本文发布于:2023-07-14 17:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1106039.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:下载器   文件   如何在   onedrive   downloader

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!