Provision of ribbon bars when using custom list definition

Oct 14, 2012 at 7:59 PM
Edited Oct 14, 2012 at 8:01 PM

Below you see some code for provision ribon bar buttons to lists based on a distinct custom list definition. I tried it with the custum action sample code. Perhaps it is helpfull for others.

 

var customActions = web.UserCustomActions;
var templateId = web.GetListTemplateIdByInternalName("InternalListDefinitionName");
ribbonCustomAction.Provision(ReceiverGuid, customActions, templateId, ListForms.ListView, null);



        /// Gets the list template by internal template name.
        /// 
        /// <param name="web" />The web.
        /// <param name="listTemplateInteralName" /> The template list interal name.
        /// 
        public static SPListTemplate GetListTemplateByInternalName(
this SPWeb web,
string listTemplateInteralName) { SPListTemplate result = null; try { foreach (SPListTemplate listTemplate in web.ListTemplates) { if (listTemplate.InternalName.ToLower().Trim()
!= listTemplateInteralName.ToLower().Trim()) continue; result = listTemplate; break; } } catch { return result; } return result; } /// /// Gets the list template id by internal template name. /// /// <param name="web" />The web. /// <param name="listTemplateInteralName" /> The template list interal name. /// public static string GetListTemplateIdByInternalName(
this SPWeb web,
string listTemplateInteralName) { return web.GetListTemplateByInternalName(
listTemplateInteralName).
Type_Client.ToString(CultureInfo.InvariantCulture); }