Get immediate child (files and folder) from folder via CSOM C# SP Online

Amit Singh Rawat 731 Reputation points
2021-08-05T07:10:22.957+00:00

Document Library
-----RootFolder -> File1
-------------------SubFolder1WithinRootFolder -> File2
------------------------------SubFolder2WithinSubFolder1 -> File3
---------------------------------------------------SubFolder3WithinSubFolder2

Hi,
I have folder object which contain files and sub folders. When I am using recursive or recursive all, it is giving me all files and folder and folder within folder etc.
I only want fetch only files and folder within specified folder. Not folder or files within its sub folder.
For e.g. if I target RootFolder it should return me File1 & SubFolder1
And when I target Subfolder1 it should return me File2 and SubFolder2

I also want item id while fetching these details.

Thanks.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,803 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,031 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amit Singh Rawat 731 Reputation points
    2021-08-05T08:24:36.547+00:00

    Below query works for me.

    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml = @"<View><Query><OrderBy Override=""TRUE""><FieldRef Name=""FileLeafRef"" /></OrderBy></Query><RowLimit>5000</RowLimit></View>";
    camlQuery.FolderServerRelativeUrl = folder.ServerRelativeUrl;

    Thanks


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.