C# 无法列出具有SharePoint客户端API的文件/文件夹
我正在尝试使用C#(C# 无法列出具有SharePoint客户端API的文件/文件夹,c#,sharepoint,sharepoint-online,sharepoint-clientobject,C#,Sharepoint,Sharepoint Online,Sharepoint Clientobject,我正在尝试使用C#(Microsoft.SharePoint.Client)中的官方SharePoint客户端库列出SharePoint联机站点中的文件和文件夹 以下是站点文件的外观: 根据URL(您可以在图中看到),我正试图这样做: using (ClientContext ctx = new ClientContext("https://*******.sharepoint.com/sites/cms")) { //Setup authentication
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.'
如果我尝试使用文件
属性而不是文件夹,也会发生这种情况
我错过了什么?
文件夹
变量似乎加载正确(调用第一个.ExecuteQuery()
后,其中的ItemsCount
属性被设置为11
),但我无法在不引发异常的情况下进一步加载。我做错了什么?嗯,我发现了问题所在
这确实是一个问题,我在哪里“分裂”的道路
我必须进一步使用网站URL:
using (ClientContext ctx = new ClientContext("https://*******.sharepoint.com/sites/cms/doc/projects"))
并从文件夹路径中删除该部分:
var folder = web.GetFolderByServerRelativeUrl("C07725");
现在它工作正常了