0

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?

0

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.

  • just perfect, I changed folder.Name with folder.Url so the user can better see the folder structure. :) – Luis Valencia Mar 8 '12 at 8:32
  • Cool that it worked! – Anatoly Mironov Mar 8 '12 at 8:47
0

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

  • its an application page. – Luis Valencia 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. – ironman Mar 8 '12 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.