Mia
Mia

Reputation: 23

how to get folder names within a sub folder in sharepoint

list.RootFolder.SubFolders[i] gives folder/subfolder name can anyone help me on how to get folder names within a subfolder in sharepoint

Upvotes: 0

Views: 5267

Answers (1)

nkvu
nkvu

Reputation: 5821

Do you have any sample code or can you show us a code sample of what has been tried to date?

It will help to answer your question if you can provide more information or tell us more about what you've tried or even post code which you have tried which you're having a specific problem with.


However, based on what I think you're after I'll try and provide a response....

One thing to watch out for is that list.RootFolder.SubFolder[i] actually returns you another SPFolder object. So you could access the SubFolders property again to get the sub-folders within that sub-folder.

This is going to be a bit of a naive example, but something like:

SPFolder subFolder = list.RootFolder.SubFolder[i];
SPFolderCollection subFoldersOfSubFolder = subFolder.SubFolders;

if (subFoldersOfSubFolder.Count > 0)
{
    for (int j = 0; j < subFoldersOfSubFolder.Count; j++)
    {
        SPFolder specificSubFolder = subFoldersOfSubFolder[j];
        /*
            At this point you could use properties like Name, 
            ServerRelativeUrl or UniqueId of the SubFolder class to get 
            the information you need.
        */
    }
}
else
{
    //If you get to here, it means that the sub-folder had no sub-folders
}

Upvotes: 1

Related Questions