Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm new to SharePoint and I'm looking to create a hierarchy of links that I can access through the API. I've tried creating a Links List, grabbing it with the SpList object and looping over the items; however, I only could seem to access the links in the list and not the folders.

So I'm not sure if I was doing something wrong or not, but I suppose I would like to know if that's the proper way to manage and access a hierarchy of links, and, if so, how I can get both the folders and links through the API? Also, if there is a better approach to managing a large list of organized links, what might it be?

It might also be worth noting that I'm working in SharePoint 2010

Thanks for the help!

share|improve this question
add comment

2 Answers

I think you probably need to make your query recursive so it can get inside the folders & show them as well. Assuming you are using a SPQuery object then the following will probably help you and is taken from MSDN:

using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"]) {

SPList oList = oWebsite.Lists["DocLib_Name"];
SPView oView = oList.Views["View_Name"];

SPQuery oQuery = new SPQuery(oView);
oQuery.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection collListItemsAvailable = 
  oList.GetItems(oQuery);

foreach (SPListItem oListItemAvailable in collListItemsAvailable)
{
    Response.Write(SPEncode.HtmlEncode(oListItemAvailable["Name"]) + 
      "<BR>");
} }
share|improve this answer
add comment

Setting the scope to recursive worked great for getting everything inside the list; however, it didn't quite do what I needed it to. Instead, I built a recursive function to loop through the items in the list and each time it found a folder, it would then loop through those items and so on. Of course, this is a pretty intensive process, so I created a class that inherited from StaticSiteMapProvider and used the SP list as its data source basically using the method described above. This also allowed for security trimming.

By the way .. Nick, sorry for taking so long to respond your post. I appreciate your help, as it set on the right path.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.