Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否有Sharepoint API可用于在站点中一次获取特定文件夹的嵌套目录结构?_Sharepoint_Sharepoint Online_Sharepoint Rest Api - Fatal编程技术网

是否有Sharepoint API可用于在站点中一次获取特定文件夹的嵌套目录结构?

是否有Sharepoint API可用于在站点中一次获取特定文件夹的嵌套目录结构?,sharepoint,sharepoint-online,sharepoint-rest-api,Sharepoint,Sharepoint Online,Sharepoint Rest Api,是否有Sharepoint API可以一次获取特定文件夹的文件/文件夹的全部内容? 我不想递归地使用GetFolderByServerRelativePath。如果不想使用GetFolderByServerRelativePath,可以将CSOM与CAML查询一起使用,如下所示: string password = "pwd"; string account = "user@Tenant.onmicrosoft.com

是否有Sharepoint API可以一次获取特定文件夹的文件/文件夹的全部内容?
我不想递归地使用GetFolderByServerRelativePath。

如果不想使用GetFolderByServerRelativePath,可以将CSOM与CAML查询一起使用,如下所示:

            string password = "pwd";
            string account = "user@Tenant.onmicrosoft.com";
            var secret = new SecureString();
            foreach (char c in password)
            {
                secret.AppendChar(c);
            }
            using (ClientContext ctx = new ClientContext("https://Tenant.sharepoint.com/sites/sitename"))
            {
                ctx.Credentials = new SharePointOnlineCredentials(account,secret);
                Web web = ctx.Web;
                ctx.Load(web);
                ctx.ExecuteQuery();
                List list = web.Lists.GetByTitle("Documents");
                ctx.Load(list);
                ctx.ExecuteQuery();
                Folder folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/shared%20documents/");
                ctx.Load(folder);
                ctx.ExecuteQuery();

                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
                                     <Query>
                                     </Query>
                                 </View>";
                camlQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;
                ListItemCollection listItems = list.GetItems(camlQuery);
                ctx.Load(listItems);
                ctx.ExecuteQuery();
                foreach (var item in listItems)
                {
                    Console.WriteLine(item.FieldValues["FileRef"].ToString());
                }
            }
string password=“pwd”;
字符串帐户=”user@Tenant.onmicrosoft.com";
var secret=new SecureString();
foreach(密码中的字符c)
{
秘密。附录字符(c);
}
使用(ClientContext ctx=newclientcontext(“https://Tenant.sharepoint.com/sites/sitename"))
{
ctx.Credentials=新的SharePointOnlineCredentials(帐户,机密);
Web=ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
列表=web.Lists.GetByTitle(“文档”);
ctx.负载(列表);
ctx.ExecuteQuery();
Folder Folder=web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl+“/shared%20documents/”;
ctx.Load(文件夹);
ctx.ExecuteQuery();
CamlQuery CamlQuery=新的CamlQuery();
camlQuery.ViewXml=@”
";
camlQuery.FolderServerRelativeUrl=folder.ServerRelativeUrl;
ListItemCollection listItems=list.GetItems(camlQuery);
ctx.Load(列表项);
ctx.ExecuteQuery();
foreach(listItems中的变量项)
{
Console.WriteLine(item.FieldValues[“FileRef”].ToString());
}
}

将同时返回所有文件夹/子文件夹/文件,希望这是您需要的。

如果不想使用GetFolderByServerRelativePath,您可以使用CSOM和CAML查询,如下所示:

            string password = "pwd";
            string account = "user@Tenant.onmicrosoft.com";
            var secret = new SecureString();
            foreach (char c in password)
            {
                secret.AppendChar(c);
            }
            using (ClientContext ctx = new ClientContext("https://Tenant.sharepoint.com/sites/sitename"))
            {
                ctx.Credentials = new SharePointOnlineCredentials(account,secret);
                Web web = ctx.Web;
                ctx.Load(web);
                ctx.ExecuteQuery();
                List list = web.Lists.GetByTitle("Documents");
                ctx.Load(list);
                ctx.ExecuteQuery();
                Folder folder = web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl + "/shared%20documents/");
                ctx.Load(folder);
                ctx.ExecuteQuery();

                CamlQuery camlQuery = new CamlQuery();
                camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
                                     <Query>
                                     </Query>
                                 </View>";
                camlQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;
                ListItemCollection listItems = list.GetItems(camlQuery);
                ctx.Load(listItems);
                ctx.ExecuteQuery();
                foreach (var item in listItems)
                {
                    Console.WriteLine(item.FieldValues["FileRef"].ToString());
                }
            }
string password=“pwd”;
字符串帐户=”user@Tenant.onmicrosoft.com";
var secret=new SecureString();
foreach(密码中的字符c)
{
秘密。附录字符(c);
}
使用(ClientContext ctx=newclientcontext(“https://Tenant.sharepoint.com/sites/sitename"))
{
ctx.Credentials=新的SharePointOnlineCredentials(帐户,机密);
Web=ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
列表=web.Lists.GetByTitle(“文档”);
ctx.负载(列表);
ctx.ExecuteQuery();
Folder Folder=web.GetFolderByServerRelativeUrl(web.ServerRelativeUrl+“/shared%20documents/”;
ctx.Load(文件夹);
ctx.ExecuteQuery();
CamlQuery CamlQuery=新的CamlQuery();
camlQuery.ViewXml=@”
";
camlQuery.FolderServerRelativeUrl=folder.ServerRelativeUrl;
ListItemCollection listItems=list.GetItems(camlQuery);
ctx.Load(列表项);
ctx.ExecuteQuery();
foreach(listItems中的变量项)
{
Console.WriteLine(item.FieldValues[“FileRef”].ToString());
}
}

将同时返回所有文件夹/子文件夹/文件,希望这是您需要的。

谢谢Jerry。实际上,我正在寻找一个API,它可以简单地以嵌套或平面格式返回内容。如果可能的话,我希望避免递归;我将更新答案,请检查,这将不需要循环子文件夹recursively@kartiksharma,您是否尝试过如上所述使用CAML查询?对你有用吗?是的,谢谢你的帮助。谢谢杰瑞。实际上,我正在寻找一个API,它可以简单地以嵌套或平面格式返回内容。如果可能的话,我希望避免递归;我将更新答案,请检查,这将不需要循环子文件夹recursively@kartiksharma,您是否尝试过如上所述使用CAML查询?对你有用吗?是的,谢谢你的帮助。