我在SharePoint中有以下路径:
我需要使用在VS 2013,Framework .Net 4.0中创建的WinForm应用程序将此文件下载并存储在我的个人计算机中。
只有直接链接存在一些实现此目的的方法吗?
答案 0 :(得分:4)
如果要异步下载,请使用:
private void buttonDownload_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadFileProgressChanged);
webClient.DownloadFileAsync(new Uri("http://example.com/myfile.xlsx"), @"c:\myfile.xlsx");
}
private void DownloadFileProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
// Update the progress bar component
progressBar.Value = e.ProgressPercentage;
}
private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Download completed!");
}
答案 1 :(得分:1)
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://example.com/myfile.txt", @"c:\myfile.txt");