Recursive trawl using the SP Client Object Model
Here’s a simple example of SP2010’s managed Client Object Model being used to build up a TreeView of subsites and lists, for a given site.
I’m using WinForms just to show the concept, if you’d like to recreate it, simply create a form and insert a TreeView control (called tv1), and a Label (called label1). Don’t forget to add a reference to Microsoft.SharePoint.Client as well.
Optionally comment out the “Short Version” and uncomment the Long - This additional code goes an extra level, i.e. it iterates through the items of each list. Bear in mind this will slow down considerably, and there is also the 5000 row List Threshold limit to take into account.
I had expected File Size to be a property in the COM (let me know if it is!) but I just couldn’t find anything related. This means we’re still stuck with dealing with CAML / Internal Names, etc. when it comes to bringing these back, e.g. File_x0020_Size :(
Check out MSDN’s Using the SharePoint Foundation 2010 Managed Client Object Model as a good starting point. The way Linq is used to ‘queue up’ only the relevant list properties we’re after, and filter the list collection to ignore hidden lists is pretty neat, makes for very simple / brief code.
Here’s a simple example of SP2010’s managed Client Object Model being used to build up a TreeView of subsites and lists, for a given site.
I’m using WinForms just to show the concept, if you’d like to recreate it, simply create a form and insert a TreeView control (called tv1), and a Label (called label1). Don’t forget to add a reference to Microsoft.SharePoint.Client as well.
Optionally comment out the “Short Version” and uncomment the Long - This additional code goes an extra level, i.e. it iterates through the items of each list. Bear in mind this will slow down considerably, and there is also the 5000 row List Threshold limit to take into account.
I had expected File Size to be a property in the COM (let me know if it is!) but I just couldn’t find anything related. This means we’re still stuck with dealing with CAML / Internal Names, etc. when it comes to bringing these back, e.g. File_x0020_Size :(
Check out MSDN’s Using the SharePoint Foundation 2010 Managed Client Object Model as a good starting point. The way Linq is used to ‘queue up’ only the relevant list properties we’re after, and filter the list collection to ignore hidden lists is pretty neat, makes for very simple / brief code.
blog comments powered by DISQUS