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

How download an Excel File from SharePoint using WinForm app

我在 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 应用程序下载此文件并将其存储在我的个人计算机中。

有一些方法可以仅通过直接 link?

来实现

使用WebClient.DownloadFile

using System.Net;

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

如果你想异步下载,使用这个:

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