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 have one application page with one dropdownlist which needs to be filled with the folders from one document library

The library has this structure

Folder1

    Folder1.1

   Folder1.2

Folder2

    Folder2.1

       Folder2.1.1

       Folder2.1.2

I would like to fill a dropdown list with the folder list in a hierarchical way if possible. It has to be server side code, not client side code.

I found something might be useful to me but it wont return the results as I want http://ranaictiu-technicalblog.blogspot.com/2010/03/sharepoint-2010-manage.html

Any idea what should I do?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Just get all subfolders recursively and populate a dropdownlist with them

var dropdownList...
var list....
var folder = list.RootFolder;
PopulateDropDownList(folder);
private void PopulateDropDownList(SPFolder folder) {
  dropdownList.Items.Add(new ListItem(folder.Name, folder.UniqueId));
  foreach(var subfolder in folder.SubFolders) {
    PopulateDropDownList(subfolder); //recursively invoke each self
  }
}

I haven't tested this code. I have just written down what I think should work.

share|improve this answer
    
just perfect, I changed folder.Name with folder.Url so the user can better see the folder structure. :) –  L.V. Sharepoint Architect Mar 8 '12 at 8:32
    
Cool that it worked! –  Anatoly Mironov Mar 8 '12 at 8:47
add comment

I've used the tree view control for something like this.

share|improve this answer
    
its an application page. –  L.V. Sharepoint Architect Mar 7 '12 at 22:58
    
I'd create a custom web part for this. That way it doesn't matter what page you add it to. –  ironman99 Mar 8 '12 at 15:06
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.