【发布时间】:2020-09-22 09:51:31
【问题描述】:
我正在尝试使用 C# 中的官方 SharePoint 客户端库 (Microsoft.SharePoint.Client) 列出 SharePoint 在线网站中的文件和文件夹。
这是网站文件的外观:
基于 URL(你可以在图片中看到它),这就是我正在尝试的方式:
using (ClientContext ctx = new ClientContext("https://*******.sharepoint.com/sites/cms"))
{
//Setup authentication
SecureString passWord = new SecureString();
foreach (char c in "mypassword".ToCharArray())
{
passWord.AppendChar(c);
}
//Connect
ctx.Credentials = new SharePointOnlineCredentials("myuser", passWord);
Web web = ctx.Web;
//Retrieve folder
var folder = web.GetFolderByServerRelativeUrl("/doc/projects/C07725");
ctx.Load(folder);
ctx.ExecuteQuery(); //This seems to work
//List subfolders
ctx.Load(folder.Folders);
ctx.ExecuteQuery(); //This throws Microsoft.SharePoint.Client.ServerException: 'File Not Found.'
}
但是最后一行,如注释中所示,抛出
Microsoft.SharePoint.Client.ServerException: 'File Not Found.'
如果我尝试使用 Files 属性而不是文件夹,也会发生这种情况。
我在这里缺少什么? folder 变量似乎已正确加载(其中的 ItemsCount 属性在调用第一个 .ExecuteQuery() 后设置为 11),但如果不引发异常,我将无法进一步了解。我在这里做错了什么?
【问题讨论】:
标签: c# sharepoint sharepoint-online sharepoint-clientobject