[英]Cannot list files/folders with the SharePoint Client API
我正在尝试使用 C# ( Microsoft.SharePoint.Client
) 中的官方 SharePoint 客户端库来列出 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
变量似乎已正确加载(在调用第一个.ExecuteQuery()
后,其中的ItemsCount
属性设置为11
),但如果不引发异常,我无法进一步了解。 我在这里做错了什么?
好吧,我发现了问题。
我“拆分”路径的位置确实存在问题。
我不得不 go 进一步访问网站 URL:
using (ClientContext ctx = new ClientContext("https://*******.sharepoint.com/sites/cms/doc/projects"))
并从文件夹路径中删除该部分:
var folder = web.GetFolderByServerRelativeUrl("C07725");
现在它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.