I am trying to do something fairly simple but seems like a near impossible task with the SharePoint API.
My SharePoint Data Structure is like:
-Folder
--- Sub Folder
--------Item A
--------Item B
--------Item C
--------Item D
For some strange reason you cannot access the Folder and subfolders in the hierarchical manner that you would expect! When I iterate over the List it will return all the items ignoring the hierarchical structure (i.e. it will return everything in the list). Worse, you don’t event know if the item is a Folder or not in order to manage the structure in code.
Now I am writing Custom Objects to make the SharePoint object model a bit more meaningful and group data in the hierarchical that I expect. I'm planning for my SharePoint items to be mapped as follows:
public class Folder
{
public Folder Parent {get; set;}
public Folder Root {get; set;}
public IList<Item> Items {get; set;}
}
Has anyone done something similar or how did you manage this limitation in SharePoint?
Is there any lessons learned and things to watch out for if I start mapping to my custom object model?
EDIT:
My final solution was too loop through the folder starting from list.RootFolder.SubFolders.
var query = from SPList list in Utils.GetList(webRelativeUrl, listName)
from SPFolder folder in list.RootFolder.SubFolders
where folder.Name.ToLower() != "forms"
select new Folder //Custom Object
{
Name = folder.Name,
Children = (from SPFolder subFolder in folder.SubFolders //Further looping of sub folders
select new Folder
{
Name = subFolder.Name,
Items = (from SPFile file in subFolder.Files
select new Item
{
//Mapping code omitted
} ).ToList()
}
{)
}
return query.ToList();