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 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 http://msdn.microsoft.com/en-us/library/ff407837.aspx. 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

1 Answer 1

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? –  L.V. Sharepoint Architect 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. –  L.V. Sharepoint Architect 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

 
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.