用于按层次结构顺序检索 ListItems 的 CAML 查询

发布于 2024-12-03 14:35:14 字数 515 浏览 2 评论 0原文

我想知道是否可以对从 SharePoint 返回的列表项进行排序(使用客户端对象 API),以便它们按层次结构排序,而不是按创建的顺序排序。

这是保持文件夹结构完整的需要。例如,如果这是一个结构:

folder001
-folder001_sub001
--item001
--item002
-folder002_sub002
--folder002_sub002_sub001
---item003
--item004
-item005

将以相同的顺序或至少以这种方式返回(首先是项目,然后是文件夹):

folder001
-item005
-folder001_sub001
--item001
--item002
-folder002_sub002
--item004
--folder002_sub002_sub001
---item003

这可以通过 CAML 查询实现吗?默认情况下按创建顺序返回事物(按列表内的索引号)

提前谢谢您!

I was wondering if it possible to order listitems coming back from SharePoint (using Client Object API) so that they are ordered hierarchly, and not in the order they were created.

This is need to keep the folder structure intact. So for example if this was a structure:

folder001
-folder001_sub001
--item001
--item002
-folder002_sub002
--folder002_sub002_sub001
---item003
--item004
-item005

would be returned in the same order or at least this way (items first, then folders):

folder001
-item005
-folder001_sub001
--item001
--item002
-folder002_sub002
--item004
--folder002_sub002_sub001
---item003

Is this possible with CAML query? Default is to return things in order they were created (by index number inside the list)

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你只要分分秒秒 2024-12-10 14:35:14

在这种情况下,我宁愿使用客户端对象模型而不是 caml。你可以做这样的事情(未经测试!):

void RecursiveListFolder(Folder folder, int indent = 0)
{
    clientContext.Load(folder.Folders);
    clientContext.ExecuteQuery();
    foreach (Folder folder in folder.Folders)
    {
        Console.WriteLine(new string(' ', indent) + folder.Name);
        RecursiveListFolder(folder, indent + 1);
    }

    clientContext.Load(folder.Files);
    clientContext.ExecuteQuery();
    foreach (File file in folder.Files)
    {
        Console.WriteLine(new string(' ', indent) + file.Name);
    }
}

这个方法将以这种方式使用:

string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
Web web = clientContext.Web;
clientContext.Load(web.Lists);
clientContext.ExecuteQuery();
List list = web.Lists["MyList"];

RecursiveListFolder(list.RootFolder);

I would rather go with client object model instead of caml in this scenario. You could do something like this (untested!):

void RecursiveListFolder(Folder folder, int indent = 0)
{
    clientContext.Load(folder.Folders);
    clientContext.ExecuteQuery();
    foreach (Folder folder in folder.Folders)
    {
        Console.WriteLine(new string(' ', indent) + folder.Name);
        RecursiveListFolder(folder, indent + 1);
    }

    clientContext.Load(folder.Files);
    clientContext.ExecuteQuery();
    foreach (File file in folder.Files)
    {
        Console.WriteLine(new string(' ', indent) + file.Name);
    }
}

This method would be used in this way:

string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
Web web = clientContext.Web;
clientContext.Load(web.Lists);
clientContext.ExecuteQuery();
List list = web.Lists["MyList"];

RecursiveListFolder(list.RootFolder);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文