how to add a custom tab with RegistrationType=List?

Nov 13, 2013 at 3:44 PM
In this example the CustomAction element has the follow attributes that make the custom tab visible only for a document library (which has list template Id 101):

RegistrationId="101"
RegistrationType="List"

Is there an example available that lets you do something like this with Fluent Ribbon API?
Nov 13, 2013 at 10:49 PM
Edited Nov 13, 2013 at 10:51 PM
You are looking for RibbonCustomAction class and then Provision method.

In your case the code will look something like this:
var action = new RibbonCustomAction();
// here add controls, tabs, groups, whatever
action.Provision(ReceiverGuid, web, ListTypes.GenericLibrary)
The article explaining this in details and with screenshots can be found on the documentation site:
Overload for Provision method you need to use is Provision(Guid, SPWeb, ListTypes).

ListTypes enumeration reference: ListTypes Enumeration
Nov 15, 2013 at 6:11 PM
Edited Nov 15, 2013 at 6:12 PM
Thanks for your help. I'm posting my code below in case it will help somebody else.

Here are the differences from the example you refered to in the docs:
  • I added a new tab instead of adding to an existing one.
  • I used a different overload of Provision that accepts a list instead since I wanted it to show up for my custom list.
  • I had to call the corresponding overload of RemoveAllCustomizations that takes a list, otherwise the old versions of the tab weren't removed.
I think you could use more examples in the docs. Feel free to use this if you want.
[Guid("4e49cb4f-8c40-4f39-bae6-eeb2c06c3e2c")]
    public class Feature1EventReceiver : SPFeatureReceiver
    {
        Guid ReceiverGuid { get { return new Guid("4e49cb4f-8c40-4f39-bae6-eeb2c06c3e2c"); } }

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (properties.Feature.Parent as SPSite).RootWeb;

            var button1 = ControlLibrary.CreateRandomButton();
            var button2 = ControlLibrary.CreateRandomButton();

            var group = new GroupDefinition()
            {
                Id = "MyGroup",
                Title = "Custom controls",
                Template = FluentRibbon.Libraries.GroupTemplateLibrary.SimpleTemplate,
                Controls = new ControlDefinition[]
                {
                    button1,
                    button2
                }
            };


            var tab = new TabDefinition()
            {
                Id = "MyTab",
                Title = "My Custom Tab",
                Groups = new GroupDefinition[] { group }
            };
            var ribbonCustomAction = new RibbonCustomAction();
            ribbonCustomAction.AddTab(tab);

            ribbonCustomAction.Provision(ReceiverGuid, web.Lists["MyList"]);

        }


        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (properties.Feature.Parent as SPSite).RootWeb;
            RibbonCustomAction.RemoveAllCustomizations(web.Lists["MyList"], ReceiverGuid);
        }
    }