How to get the entire AND folder from the sharepoint list?

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

A folder may contain subfolders and subitems. A subfolder may contain subfolders, etc. I have already managed to get all the items and folders using this method:

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 with this solution is that I have to send a new request for each folder, which becomes unstable when the list grows. Is there a way to get the whole list in one call without losing the folder / item structure?

Thanks for reading this!

Edit: This is not a requirement to use CAML. But there is a limitation that I forgot about: I cannot use web services due to client restrictions.

+4
source share
2 answers
+6
source
 query.ViewAttributes="Scope='RecursiveAll'"; 
-1
source

All Articles