1

Closed

GetNewBreadCrumbOutput going too far up the hierarchy

description

First of all, thanks for this project! It's exactly what I was looking for. After building and deploying to a test site, I wasn't getting any breadcrumbs at all. Upon debugging, I discovered that it was throwing an exception on the nodes.Add line. The nodeFolder.Url for any given folder is in the format "/Lists/<ListName>/<Folder1>/<Folder2>/<etc>". I noticed that when this loop gets to the root folder, it's not enough to check to see if nodeFolder.ParentFolder.Url is null or empty, since it treats /Lists like a folder. Therefore, nodeFolder gets assigned the "/Lists" folder, which doesn't have DocumentLibrary associated and ends up throwing out of reference exceptions.
 
I modified the code slightly and it's working well so far. Here's what I'm using:
 
Guid rootFolderId = folder.DocumentLibrary.RootFolder.UniqueId;
        while (nodeFolder != null)
        {
            nodes.Add(new BreadcrumbNodeData { Title = (string.IsNullOrEmpty(nodeFolder.ParentFolder.Url) || nodeFolder.UniqueId.Equals(rootFolderId)) ? nodeFolder.DocumentLibrary.Title : nodeFolder.Name, Url = nodeFolder.ServerRelativeUrl });
            nodeFolder = (string.IsNullOrEmpty(nodeFolder.ParentFolder.Url) || nodeFolder.UniqueId.Equals(rootFolderId)) ? null : nodeFolder.ParentFolder;
        }
 
Hop this helps.
Closed Jul 11, 2012 at 12:14 PM by AlexBoev
Thank you very much for the useful feedback! I'm glad my little project has some value for others. The problem was that the folders-enabled lists wasn't supported - only the document libraries, look at the project title. :) So there's the difference in the folder structure for the document library and for the list with folders - there's no additional level of folders in library like "Lists" - they are placed in the root folder of the SPWeb. I've updated the solution to support both types now. See the downloads section if you prefer to use my version.

comments

AlexBoev wrote Jul 11, 2012 at 12:10 PM

Thank you very much for the useful feedback! I'm glad my little project has some value for others.

The problem was that the folders-enabled lists wasn't supported - only the document libraries, look at the project title. :) So there's the difference in the folder structure for the document library and for the list with folders - there's no additional level of folders in library like "Lists" - they are placed in the root folder of the SPWeb. I've updated the solution to support both types now. See the downloads section if you prefer to use my version.

wrote Jul 11, 2012 at 12:14 PM

ronx wrote Jul 12, 2012 at 1:19 PM

I'll take a look at your updated code. I was referring to Document Libraries, though, which by default may contain folders. Keep in mind that Document Libraries may indeed have additional levels of folders, depending on how they were created. For example, the default in SP2007 was for document libraries to be created under the Lists folder. I had a custom solution for 2007 that defined some lists declaratively. When I reworked the solution for 2010, I left the Document Library paths the same, so they were created under the /Lists/ folder. Other folks may have similar organizational needs. For this reason, I think it is a good idea to check the current folder ID against the RootFolder ID when walking up the hierarchy.

AlexBoev wrote Jul 15, 2012 at 11:56 AM

@ronx: thanks a lot again for clarification. I didn't know there're the cases when the library is in the "lists" folder too. But I think my solution should work in this case - it simply ignores Lists folder. I can't reproduce this case so write me please if it doesn't work - I'll try to adopt your solution then.

wrote Feb 14, 2013 at 12:45 AM

wrote May 16, 2013 at 6:25 AM