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

本文关键字:下载 Excel 文件 SharePoint 何使用 WinForm 应用程序 | 更新日期: 2023-09-27 18:02:43

我在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% - 20 and%20ws%20poss.xlsx

我需要下载并存储这个文件在我的个人电脑使用在VS 2013中创建的WinForm应用程序,框架。net 4.0。

是否存在仅使用直接链接实现此目的的方法?

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

如果您想要异步下载,请使用:

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

使用WebClient。DownloadFile

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