I found a working solution on my own:
http://blog.krichie.com/2007/01/30/traversing-sharepoint-list-folder-hierarchies/
Edit (5 years later):
From the site mentioned above
It’s actually very easy, but I would vote it’s a horrible way to have
to go about it.
Enter SPQuery:
private static void TraverseListFolder(SPFolder folder)
{
// Get the collection of items from this folder
SPQuery qry = new SPQuery();
qry.Folder = folder;
SPWeb web = null;
try {
web = folder.ParentWeb;
SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);
foreach (SPListItem subitem in ic){
Console.WriteLine(“List item: “ + subitem.Name);
Console.WriteLine(“List item type: “ + subitem.ContentType.Name);
if (subitem.Folder != null)
TraverseListFolder(subitem.Folder);
}
} catch (Exception e) {
Console.WriteLine(e.Message);
} finally {
// Cleanup that nasty web reference.
if (web != null)
web.Dispose();
}
}
Ok so cool, we now have a way to get ONLY the items in a folder within
a list at any level without introducing any items that are not in
scope.
So, we’ll just use this method, and to traverse the list, but hey,
where do you start? Well, fortunately SPList exposes a RootFolder
property that gives you a SPFolder object to start with J
So we can write our List traversal Kick off method as such:
private static void TraverseList(SPList list)
{
Console.WriteLine(“Traversing list: “ + list.Title);
Console.WriteLine(“Base Type: “ + list.BaseType.ToString());
TraverseListFolder(list.RootFolder);
}
Simply pass in a reference to a list, and away we go. Very compact,
and it works regardless if the list being passed in is a Document
Library or any kind of list.