read subfolders in specifed folder

%3CLINGO-SUB%20id%3D%22lingo-sub-1171179%22%20slang%3D%22en-US%22%3Eread%20subfolders%20in%20specifed%20folder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1171179%22%20slang%3D%22en-US%22%3E%3CP%3EHello.%20I%20need%20read%20subfolders%20in%20specifed%20folder.%3C%2FP%3E%3CP%3EList%3CSTRING%3E%20levels%20%3D%20catalog.Split('%5C%5C').ToList()%3B%20%2F%2F%20catalog%20is%20input%20parameter%2C%3CBR%20%2F%3E%2F%2F%20for%20example%3A%20catalog%20catalog%20%3D%20%22DocsLibrary%5C%5CClients%5C%5C%22%3B%3C%2FSTRING%3E%3C%2FP%3E%3CP%3Elevels.RemoveAt(levels.Count%20-%201)%3B%20%2F%2Flevels%20Count%20%3D%202%20%5B0%5D%3A%20%22DocsLibrary%22%20%5B1%5D%3A%20%22Clients%22%3C%2FP%3E%3CP%3EI%20split%20catalog%20and%20try%20to%20understand%2C%20if%20each%26nbsp%3BfolderName%20%3D%20levels%5Bi%5D%20exists%20in%20rootFolder.%20If%20exists%20I%2C%20take%20this%20subfolder%20and%20try%20to%20get%20subfolder.folders%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EList%20list%20%3D%20contextSP.Web.Lists.GetByTitle(%22Documents%22)%3B%3C%2FP%3E%3CP%3Evar%20currentfolder%20%3D%20list.RootFolder%3B%3CBR%20%2F%3EcontextSP.Load(currentfolder%2C%20f%20%3D%26gt%3B%20f.Folders%2C%20f%20%3D%26gt%3B%20f.ServerRelativeUrl)%3B%3CBR%20%2F%3EcontextSP.ExecuteQuery()%3B%3C%2FP%3E%3CP%3Evar%20ourfolders%20%3D%20currentfolder.Folders.ToList()%3B%20%2F%2F%20ourfolders%5B0%5D.Name%20%22DocsLibrary%22%3CBR%20%2F%3Estring%20currentfolderurl%20%3D%20null%3B%3C%2FP%3E%3CP%3Efor%20(int%20i%20%3D%200%3B%20i%20%26lt%3B%20levels.Count%3B%20i%2B%2B)%3CBR%20%2F%3E%7B%3CBR%20%2F%3Estring%20folderName%20%3D%20levels%5Bi%5D%3B%3C%2FP%3E%3CP%3Eif%20(!ourfolders.Where(x%20%3D%26gt%3B%20x.Name%20%3D%3D%20folderName).Any())%3CBR%20%2F%3E%7B%3CBR%20%2F%3Ereturn%20dict%3B%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eelse%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%2F%2FRetrieve%20current%20folder's%20folders%3CBR%20%2F%3Ecurrentfolder%20%3D%20ourfolders.Where(x%20%3D%26gt%3B%20x.Name%20%3D%3D%20folderName).First()%3B%3CBR%20%2F%3EcontextSP.Load(currentfolder%2C%20f%20%3D%26gt%3B%20f.Folders%2C%20f%20%3D%26gt%3B%20f.ServerRelativeUrl)%3B%3CBR%20%2F%3EcontextSP.ExecuteQuery()%3B%3C%2FP%3E%3CP%3E%7D%3CBR%20%2F%3Ecurrentfolderurl%20%3D%20currentfolder.ServerRelativeUrl%3B%3CBR%20%2F%3Eourfolders%20%3D%20currentfolder.Folders.ToList()%3B%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3Efor%20i%3D0%20I%20receive%2013%20subfolders(its%20right%20number)%2C%20in%20next%20iteration%20I%20must%20read%20approximately%2066.000%20records%2C%20but%20ourfolders.Count%20%3D%200%3C%2FP%3E%3CP%3EWhy%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor

Hello. I need read subfolders in specifed folder.

List<string> levels = catalog.Split('\\').ToList(); // catalog is input parameter,
// for example: catalog catalog = "DocsLibrary\\Clients\\";

levels.RemoveAt(levels.Count - 1); //levels Count = 2 [0]: "DocsLibrary" [1]: "Clients"

I split catalog and try to understand, if each folderName = levels[i] exists in rootFolder. If exists I, take this subfolder and try to get subfolder.folders


List list = contextSP.Web.Lists.GetByTitle("Documents");

var currentfolder = list.RootFolder;
contextSP.Load(currentfolder, f => f.Folders, f => f.ServerRelativeUrl);
contextSP.ExecuteQuery();

var ourfolders = currentfolder.Folders.ToList(); // ourfolders[0].Name "DocsLibrary"
string currentfolderurl = null;

for (int i = 0; i < levels.Count; i++)
{
string folderName = levels[i];

if (!ourfolders.Where(x => x.Name == folderName).Any())
{
return dict;
}
else
{
//Retrieve current folder's folders
currentfolder = ourfolders.Where(x => x.Name == folderName).First();
contextSP.Load(currentfolder, f => f.Folders, f => f.ServerRelativeUrl);
contextSP.ExecuteQuery();

}
currentfolderurl = currentfolder.ServerRelativeUrl;
ourfolders = currentfolder.Folders.ToList();
}

for i=0 I receive 13 subfolders(its right number), in next iteration I must read approximately 66.000 records, but ourfolders.Count = 0

Why ?

 

0 Replies