1

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.

1 Answer 1

1

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
                }
                ");

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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