简体   繁体   English

优化 CSOM 加载时间以从 SharePoint 树中获取所有文件

[英]Optimize CSOM loading time to get all files from SharePoint tree

so i'm trying to implement a function to get every files from a SharePoint tree.所以我试图实现一个函数来从 SharePoint 树中获取每个文件。 The function works fine except for the loading time of it.除了加载时间外,该功能工作正常。

Here is what i've done这是我所做的

    private List<ListItem> GetAllItems(ClientContext Context, List list, List<ListItem> ListItems, CamlQuery camlQuery)
        {
            camlQuery.ViewXml =
                    @"< View Scope = 'RecursiveAll'>
                        < Query >
                            <Where>
                          </Where>
                        </ Query >
                    </ View >";

            ListItemCollection AllItems = list.GetItems(camlQuery);
            Context.Load(AllItems);
            Context.ExecuteQuery();
            foreach (ListItem item in AllItems)
            {
                if (item.FileSystemObjectType == FileSystemObjectType.File)
                {
                    if (!ListItems.Contains(item))
                        ListItems.Add(item);
                }

                if (item.FileSystemObjectType == FileSystemObjectType.Folder)
                {
                    camlQuery.FolderServerRelativeUrl = item.FieldValues["FileRef"].ToString();
                    GetAllItems(Context, list, ListItems, camlQuery);
                }
            }

            return ListItems;
        }

The problem is Context.ExecuteQuery();问题是Context.ExecuteQuery(); is taking me 0,3 - 1s to load each query and for a tree where i have 1424 folders it took me more than 4 min to load and it would be too long if the number of folders gets bigger.加载每个查询需要 0,3 - 1 秒,对于一棵树,我有 1424 个文件夹,加载时间超过 4 分钟,如果文件夹数量变大,时间会太长。

So i want to ask is there any possibility to reduce loading time of this or is there anyway that is more optimal to get every files from a SharePoint tree?所以我想问一下是否有可能减少加载时间,或者是否有更优化的方式从 SharePoint 树中获取每个文件?

This is an article about optimizing CSOM code for your reference: https://www.codeproject.com/Articles/738008/Programming-Efficiently-with-the-SharePoint-Client这是一篇关于优化CSOM代码的文章,供大家参考: https : //www.codeproject.com/Articles/738008/Programming-Efficiently-with-the-SharePoint-Client

Main idea:大意:

  1. Only Request What You Want (But request everything you want in one go!)只请求你想要的(但一次性请求你想要的一切!)
  2. Call ExecuteQuery Sparingly谨慎调用 ExecuteQuery
  3. Advanced: Parallel and Async Code高级:并行和异步代码
  4. Caching Data in the Session在会话中缓存数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM