gpt4 book ai didi

c# - 无法下载 Office 365 SharePoint 库项目

转载 作者:行者123 更新时间:2023-11-30 19:18:28 29 4
gpt4 key购买 nike

我正在尝试使用 WebcClient.DownloadFile() 下载 Office 365 SharePoint 库中存在的项目,但出现此异常:

异常:

The remote server returned an error: (403) Forbidden.

示例代码:

NetworkCredential credential = new NetworkCredential("username", "password", "aaa.onmicrosoft.com");
WebClient webClient = new WebClient();
webClient.Credentials = credential;
webClient.DownloadFile(@"https://aaa.sharepoint.com/testDoc/test.pdf", @"c:/test.pdf");

最佳答案

另一种选择是利用 SharePointOnlineCredentials class来自 SharePoint Online Client Components SDK .

SharePointOnlineCredentials class表示一个提供凭据以访问 SharePoint Online 资源的对象

先决条件

SharePoint Online Client Components SDK

如何从 SharePoint Online 下载文件

 public static void DownloadFile(string userName, string password, string fileUrl, string filePath)
{
var securePassword = new SecureString();
foreach (var c in password)
{
securePassword.AppendChar(c);
}
using (var client = new WebClient())
{
client.Credentials = new SharePointOnlineCredentials(userName, securePassword);
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
client.DownloadFile(fileUrl, filePath);
}
}

关于c# - 无法下载 Office 365 SharePoint 库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12671194/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com