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 already have created a dropdownlist in the ribbon, however I need to fill it with the folders inside the Site pages library for example.

I tried, but I didnt find any article or blog about it.

here is the code I have so far.

What I want is to put a move button, and when the user selects some html files, they will be able to move the files to the selected folder.

I found here how to get a folder list, but I need a folder list of the site pages library only, NOT all folders.

share|improve this question
up vote 1 down vote accepted

You need to render a javascript for the populate command that you specified in your XML on the same page. You can render it with custom webpart or delegate control for example.

UPDATE: Although there is a bunch of methods to get all the folders from the library here's the one I've quickly tested for you in the Site Pages library:

SPList list = SPContext.Current.Web.Lists.TryGetList("Site Pages");
List<SPFolder> allFolders = list.Folders.OfType<SPListItem>().Select(li => li.Folder).ToList();

And so all you need is to provide a function to PopulateQueryCommand See the example from Chris O'Brien here. Note the getDropdownItemsXml function used as the source of the data for PopulateQueryCommand. My additional advice for you is to not use a page component like in this example - this technique useful for really big Ribbon modifications. For your simple task the simple JS function is enough.

And finally - this is the one way to render population function on the page from the server side - I've created a web part code for this:

public class JSRenderWebPart : WebPart
        protected override void CreateChildControls()
            Page.RegisterClientScriptBlock("DropDownPopulateFunction", @"
                function PopulateDropDowm()
                    // render your population logic here

share|improve this answer
please see the edit, is it possible to fetch only the folders from a specific pagelibrary? Not all folders? – Esteban V Mar 2 '12 at 14:44
Do you need all the folders recursive or just at the root level or something else? – Alex Boev Mar 2 '12 at 15:21
indeed, recursive. – Esteban V Mar 2 '12 at 15:32
See the update. – Alex Boev Mar 2 '12 at 16:12
I've added a function rendering example too. Ask if there's something unclear still. – Alex Boev Mar 2 '12 at 17:54

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.