private string GetRibbonLocationByListForms(ListForms whichForms) { switch (whichForms) { case ListForms.ListView: case ListForms.NewForm: case ListForms.EditForm: case ListForms.DisplayForm: return("CommandUI.Ribbon." + whichForms.ToString()); case ListForms.All: return("CommandUI.Ribbon"); default: throw new Exception("Impossible list forms value."); } }
/// <summary> /// Provision all pending customizations to specified web. /// Customizations will be shown on specified list pages, for lists with specified ID (this can be your custom list template ID), /// to users with appropriate rights. /// </summary> /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param> /// <param name="userCustomActions">Collection of custom actions of web or list (web.UserCustomActions or list.UserCustomActions)</param> /// <param name="templateId">Custom list template Id, for which ribbon elements will be registered</param> /// <param name="whichForms">List forms, which will display the ribbon</param> /// <param name="rights">Rights user needs to access the ribbon</param> /// <returns>Id of provisioned custom action</returns> // Overloads for this method are in "RibbonCustomAction/ProvisionOverloads.cs" public Guid Provision(Guid featureUniqueGuid, SPUserCustomActionCollection userCustomActions, string templateId, ListForms whichForms, SPBasePermissions?rights) { var customAction = userCustomActions.Add(); customAction.Name = "Hemrika.SharePresence.Common.Ribbon._" + featureUniqueGuid.ToString().Replace("-", "") + "._" + Guid.NewGuid().ToString().Replace("-", ""); customAction.Location = GetRibbonLocationByListForms(whichForms); customAction.CommandUIExtension = XmlGenerator.Current.GetCommandUIExtensionXML(RibbonXML, RibbonCommandsXML, RibbonTemplatesXML); if (customAction.Scope != SPUserCustomActionScope.List) { if (String.IsNullOrEmpty(templateId) || templateId == ((int)ListTypes.All).ToString()) { customAction.RegistrationType = SPUserCustomActionRegistrationType.ContentType; customAction.RegistrationId = "0x"; } else if (templateId != ((int)ListTypes.None).ToString()) { customAction.RegistrationType = SPUserCustomActionRegistrationType.List; customAction.RegistrationId = templateId; } } if (rights.HasValue) { customAction.Rights = rights.Value; } customAction.Update(); return(customAction.Id); }
/// <summary> /// Provision all pending customizations to specified list. /// Customizations will be shown on specified list pages for lists with specified ID. /// </summary> /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param> /// <param name="list">SPList, where a ribbon will be added</param> /// <param name="whichForms">List forms, which will display the ribbon</param> /// <returns>Id of provisioned custom action</returns> public Guid Provision(Guid featureUniqueGuid, SPList list, ListForms whichForms) { return(ProvisionList(featureUniqueGuid, list, string.Empty, whichForms, null)); }
/// <summary> /// Provision all pending customizations to specified web. /// Customizations will be shown on specified list pages, only to users with appropriate rights. /// </summary> /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param> /// <param name="list">SPList, where a ribbon will be added</param> /// <param name="whichForms">List forms, which will display the ribbon</param> /// <param name="rights">Minimal privilegies, needed to see the ribbon elements</param> /// <returns>Id of Provisioned custom action</returns> public Guid Provision(Guid featureUniqueGuid, SPList list, ListForms whichForms, SPBasePermissions rights) { return(ProvisionList(featureUniqueGuid, list, string.Empty, whichForms, rights)); }
/// <summary> /// /// </summary> /// <param name="featureUniqueGuid"></param> /// <param name="list"></param> /// <param name="templateId"></param> /// <param name="whichForms"></param> /// <param name="rights"></param> /// <returns></returns> private Guid ProvisionList(Guid featureUniqueGuid, SPList list, string templateId, ListForms whichForms, SPBasePermissions?rights) { var id = Provision(featureUniqueGuid, list.UserCustomActions, templateId, whichForms, rights); list.Update(); return(id); }
/// <summary> /// Provision all pending customizations to specified site collection. /// Customizations will be shown on specified list pages, only to users with appropriate rights. /// </summary> /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param> /// <param name="site">Site collection, to which the ribbon customizations will be provisioned</param> /// <param name="listType">One of standard list types, for which ribbon elements will be registered</param> /// <param name="whichForms">List forms, which will display the ribbon</param> /// <param name="rights">Minimal privilegies, needed to see the ribbon elements</param> /// <returns>Id of Provisioned custom action</returns> public Guid Provision(Guid featureUniqueGuid, SPSite site, ListTypes listType, ListForms whichForms, SPBasePermissions rights) { return(ProvisionSite(featureUniqueGuid, site, ((int)listType).ToString(), whichForms, rights)); }
/// <summary> /// Provision all pending customizations to specified site collection. /// Customizations will be shown on specified list pages for lists with specified ID. /// </summary> /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param> /// <param name="site">Site collection, to which the ribbon customizations will be provisioned</param> /// <param name="listType">One of standard list types, for which ribbon elements will be registered</param> /// <param name="whichForms">List forms, which will display the ribbon</param> /// <returns>Id of provisioned custom action</returns> public Guid Provision(Guid featureUniqueGuid, SPSite site, ListTypes listType, ListForms whichForms) { return(ProvisionSite(featureUniqueGuid, site, ((int)listType).ToString(), whichForms, null)); }
/// <summary> /// /// </summary> /// <param name="featureUniqueGuid"></param> /// <param name="site"></param> /// <param name="templateId"></param> /// <param name="whichForms"></param> /// <param name="rights"></param> /// <returns></returns> private Guid ProvisionSite(Guid featureUniqueGuid, SPSite site, string templateId, ListForms whichForms, SPBasePermissions?rights) { return(Provision(featureUniqueGuid, site.UserCustomActions, templateId, whichForms, rights)); }
/// <summary> /// Provision all pending customizations to specified web. /// Customizations will be shown on specified list pages for lists with specified ID. /// </summary> /// <param name="featureUniqueGuid">Guid, needed for feature-scoped cleanup in FeatureDeactivating using <see cref="RibbonCustomAction.RemoveAllCustomizations"/> method.</param> /// <param name="site">SPWeb, where a ribbon will be added</param> /// <param name="listType">One of standard list types, for which ribbon elements will be registered</param> /// <param name="whichForms">List forms, which will display the ribbon</param> /// <returns>Id of provisioned custom action</returns> public Guid Provision(Guid featureUniqueGuid, SPWeb web, ListTypes listType, ListForms whichForms) { return(ProvisionWeb(featureUniqueGuid, web, ((int)listType).ToString(), whichForms, null)); }