Wednesday, August 22, 2007

Traversing lists in MOSS 2007

As you all might or might not know, WSS 3.0 and MOSS 2007 support folders in lists. This is honestly a really cool feature/enhancement to the list functionality. This opens the door to a lot more possibilities.

However, you need to be a little careful with traversing lists that you create folder heirarchies in. Traversing a list is not as obvious as you think. I was a little surprised that the solution was not intuitive.

Here are some of the caveats that I discovered:
1. A call to list.Items will not bring forth your folders. Instead, it will bring forth ALL the regular items, regardless of the folder heirarchy they live in. So it doesnt matter if an item is at the root level or 4 levels deep - it will show up in the call to list.Items.

2. We have another property available for the folders :). However, a call to list.Folders will bring forth all the folders regardless of their heirarchy in the list.

Keith Ritchie has a solution that works and he has done good homework around this problem. Be sure to have a look at his post here.