我尝试建立一个应用程序商店,但我的下载程序有问题我尝试创建一个文件下载程序,但它根本不工作! 我的视觉效果仍然告诉我,我的应用程序在代码上没有任何错误! 我认为从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!");
}
答案 0 :(得分:4)
我猜你的网址是错的。如果您共享指向文件的链接,则显示如下:
https://onedrive.live.com/redir?resid=698A32FCADE8DFDA%2121825
您必须将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");
作为替代方案,您只需在浏览器中打开此链接,该文件将自动下载到您的下载目录:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {file: "commonAddWidget.js"};
});