none
Sharepoint online ListItems over 5000 documents RRS feed

  • Question

  • hi,I am facing the issue of getting list items like tree view  <View Scope='RecursiveAll'>
                        <Query>
                            <Where>
                                <Eq>
                                    <FieldRef Name='FileDirRef' />
                                    <Value Type='Text'>{0}</Value>
                                </Eq>
                            </Where>
                        </Query>
                        <RowLimit>{1}</RowLimit>
                    </View> caml query for onprem no issue,but for o365 items over 5000 it shows error.

    Please assisst me.


    Sai Monesh.cs

    Wednesday, November 27, 2019 4:51 PM

All replies

  • This is a limitation in O365. You need to either index the columns used in the CAML query or start archiving items in the list, to reduce their number.

    [SharePoint lurker]

    Wednesday, November 27, 2019 10:37 PM
  • Hi,

    “By default, the list view threshold is configured at 5,000 items. When the defined item limit in a list is exceeded, the message is displayed.”

    https://docs.microsoft.com/en-us/sharepoint/support/lists-and-libraries/items-exceeds-list-view-threshold#more-information

    If the total files count under the specific folder doesn’t exclude this limit, use recursive function to read the files.

    Folder folder = context.Web.GetFolderByServerRelativeUrl("/sites/yoursite/largeLib1/set1");
                    context.Load(folder.Files);
                    context.Load(folder.Folders);
                    context.ExecuteQuery();
    
                    foreach(var file in folder.Files)
                    {
                        Console.WriteLine(file.ServerRelativeUrl);
                    }
    
                    foreach(var _Folder in folder.Folders)
                    {
                        File[] allfiles= getFolderFiles(context, _Folder);
                        foreach(var myFile in allfiles)
                        {
                            Console.WriteLine(myFile.ServerRelativeUrl);
                        }
                    }
    
     static File[] getFolderFiles(ClientContext context, Folder folder)
            {
                File[] files;
                var tmpFiles = folder.Files;
                var tmpFolders = folder.Folders;
                context.Load(tmpFiles);
                context.Load(tmpFolders);
                context.ExecuteQuery();
                files = tmpFiles.ToArray();
                foreach(var _F in tmpFolders)
                {
                    File[] results= getFolderFiles(context, _F);
                    files=files.Concat(results).ToArray();
                    Console.WriteLine(files.Count());
                }
                return files;
    
            }

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, November 28, 2019 3:09 AM
  • Hi this doesn't work if the list contains over 5000 items


    Sai Monesh.cs

    Wednesday, December 4, 2019 2:31 PM
  • Hi

    The code is tested in a library over 10K files, while the files in the specific folder less than 100.

    If the files in the folder large than 5k, you need get all items with pagination and then filter.

    Get all items, you could check the code in below thread.

    https://www.magnetismsolutions.com/blog/dominicjarvis/2018/05/18/paging-caml-queries-in-c----microsoft-sharepoint-online

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, December 5, 2019 9:18 AM