SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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








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

Any idea what should I do?

share|improve this question
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;
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. :) – Esteban V Mar 8 '12 at 8:32
Cool that it worked! – Anatoly Mironov Mar 8 '12 at 8:47

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

share|improve this answer
its an application page. – Esteban V 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 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.