如何使用WinForm应用程序从SharePoint下载Excel文件

时间:2015-07-14 15:03:20

标签: c# excel winforms sharepoint

我在SharePoint中有以下路径:

http://xxxx.xxx.com/bu/PSCLA/Document_3/LA%20Sites/Rio/Site%20OP%20Strategy/Master%20Data%20Audit%20Hair%20Care%20Rio%20Plant/MRP%201-4%20and%20WS%20POSS.xlsx

我需要使用在VS 2013,Framework .Net 4.0中创建的WinForm应用程序将此文件下载并存储在我的个人计算机中。

只有直接链接存在一些实现此目的的方法吗?

2 个答案:

答案 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)

使用WebClient.DownloadFile

using System.Net;

WebClient webClient = new WebClient();
webClient.DownloadFile("http://example.com/myfile.txt", @"c:\myfile.txt");