如何从共享点列表中获取所有文件夹和项目?

发布于 2024-12-12 12:38:17 字数 1534 浏览 2 评论 0原文

我有一个包含文件夹和项目的列表。文件夹是基于文件夹的特定内容类型,但具有属性。

文件夹可以包含子文件夹和子项目。子文件夹可以包含子子文件夹等等。我已经设法使用这种方式获取所有项目和文件夹:

    void TraverseList(SPList list)
    {
        Trace.WriteLine("Traversing list: " + list.Title);
        Trace.WriteLine("Base type: " + list.BaseType.ToString());
        TraverseListFolder(list.RootFolder);
    }

    void TraverseListFolder(SPFolder folder)
    {
        SPQuery qry = new SPQuery();
        qry.Folder = folder;
        Trace.WriteLine("Foldername: " + folder.Name);
        SPWeb web = null;

        try
        {
            web = folder.ParentWeb;
            SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);

            foreach (SPListItem subitem in ic)
            {
                SPFieldLookupValue temp = new SPFieldLookupValue(subitem["TargetPage"].ToString());
                Trace.WriteLine("TargetPage: " + temp);
                Trace.WriteLine("ItemName: " + subitem.Name);
                if (subitem.Folder != null)
                {
                    TraverseListFolder(subitem.Folder);
                }
            }
        }
        catch (Exception ex)
        {
            Trace.WriteLine(ex.Message);
            throw;
        }
        finally
        {
            if (web != null)
            {
                web.Dispose();
            }
        }
    }

此解决方案中的问题是我必须为每个文件夹发送一个新查询,当列表不断增长时,这会变得性能不佳。有没有一种方法可以通过一次调用获取整个列表,而不丢失文件夹/项目结构?

感谢您阅读本文!

编辑:使用 CAML 不是必需的。但有一个限制我忘记了:由于客户限制,我无法使用网络服务。

I have a list containing folders and items. The folders are a specific content type based on folder, but with properties.

A folder can contain subfolders and subitems. A subfolder can contain sub-subfolders and so on. I already managed to get all items and folders using this way:

    void TraverseList(SPList list)
    {
        Trace.WriteLine("Traversing list: " + list.Title);
        Trace.WriteLine("Base type: " + list.BaseType.ToString());
        TraverseListFolder(list.RootFolder);
    }

    void TraverseListFolder(SPFolder folder)
    {
        SPQuery qry = new SPQuery();
        qry.Folder = folder;
        Trace.WriteLine("Foldername: " + folder.Name);
        SPWeb web = null;

        try
        {
            web = folder.ParentWeb;
            SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);

            foreach (SPListItem subitem in ic)
            {
                SPFieldLookupValue temp = new SPFieldLookupValue(subitem["TargetPage"].ToString());
                Trace.WriteLine("TargetPage: " + temp);
                Trace.WriteLine("ItemName: " + subitem.Name);
                if (subitem.Folder != null)
                {
                    TraverseListFolder(subitem.Folder);
                }
            }
        }
        catch (Exception ex)
        {
            Trace.WriteLine(ex.Message);
            throw;
        }
        finally
        {
            if (web != null)
            {
                web.Dispose();
            }
        }
    }

The problem in this solution is that I have to send a new query for every folder, which is getting imperformant when the list is growing. Is there a way to get the whole list with one call, without loosing the folder/item structure?

Thank you for reading this!

Edit: It's not a requirement to use CAML. But there is a restriction I forgot: I'm not able to use webservices, due to customer restrictions.

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

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

发布评论

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

评论(2

╰沐子 2024-12-19 12:38:17
query.ViewAttributes="Scope='RecursiveAll'";
query.ViewAttributes="Scope='RecursiveAll'";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文