I've trying to build a tree view which will show a Sites Lists and folders. This is an external application so I have to communicate with WSS3 through web services.
Site
|-List
| |-Folder
| |-Folder
| |-Folder
|
|-List
| |-Folder
|
|-List
I was able to drill down from my SPWeb.Lists
object to get the SPListCollection
. However from the SPList.Folders
collection you get the SPListItemCollection
, not SPFolderCollection
.
There doesn't appear to be a property for child objects in the SPList
object.
As you can't cast SPListItem
to SPFolder
I got the SPFolderCollection
directly from SPWeb.Folders
instead but this seems to return odd things.
I have a List called "Developer" which contains a folder called "First" that has a subfolder called "Deeper".
This is the recursive method I wrote to create nodes for the folders.
private TreeNode[] CreateBranch(SPFolder folder)
{
if (folder.SubFolders.Count > 0)
{
List<TreeNode> branchList = new List<TreeNode>();
TreeNode child;
foreach (SPFolder item in folder.SubFolders)
{
if (item.SubFolders.Count > 0)
// Start recursion
child = new TreeNode(item.Name, CreateBranch(item));
else
child = new TreeNode(item.Name);
// Collect folders
branchList.Add(child);
}
return branchList.ToArray();
}
return null;
}
This builds me a tree, as it should, but SubFolders of Folders do not seem to appear in the collection as a looped through it at all. The "Developer" list also came up as a folder, as well as the web directories.
This has left me a little confused at which collection I should be using and how I am supposed to tell if a folder has subfolders at all. Can anyone help point me in the right direction?