我尝试建立一个应用程序商店但我的下载程序有问题我尝试创建一个文件下载程序,但它根本不工作! 我的视觉仍然告诉我,我的应用程序没有任何代码错误! 我认为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");更多推荐
发布评论