Hi,
Recently I was assigned a task to find out programmatically if a particular button is already defined on an entity or not. For this we can make use RetrieveEntityRibbonRequest class.
Sample C# Code
// Initialize RetrieveEntityRibbonRequest RetrieveEntityRibbonRequest ribbonReq = new RetrieveEntityRibbonRequest(); // RibbonLocationFilters // All - Retrieve all Ribbons. Equivalent to Default. Value = 7. // Default - Retrieve all Ribbons. Equivalent to All. Value = 7. // Form - Retrieve just the form ribbon. Value = 1. // HomepageGrid - Retrieve just the ribbon displayed for entity grids. Value = 2. // SubGrid - Retrieve just the ribbon displayed when the entity is displayed in a subgrid or associated view. Value = 4. // if not specified it returns only the definition ribbonReq.RibbonLocationFilter = RibbonLocationFilters.All; // specify the entity schema name ribbonReq.EntityName = currentEntityName; RetrieveEntityRibbonResponse ribbonRes = (RetrieveEntityRibbonResponse)_serviceProxy.Execute(ribbonReq); Byte[] bytes = unzipRibbon(ribbonRes.CompressedEntityXml); string ribbonDiffString = System.Text.Encoding.GetEncoding("utf-8").GetString(bytes); if (ribbonDiffString.Contains("RibbonButtonID")) { // logic } public byte[] unzipRibbon(byte[] data) { System.IO.Packaging.ZipPackage package = null; MemoryStream memStream = null; memStream = new MemoryStream(); memStream.Write(data, 0, data.Length); package = (ZipPackage)ZipPackage.Open(memStream, FileMode.Open); ZipPackagePart part = (ZipPackagePart)package.GetPart(new Uri("/RibbonXml.xml", UriKind.Relative)); using (Stream strm = part.GetStream()) { long len = strm.Length; byte[] buff = new byte[len]; strm.Read(buff, 0, (int)len); return buff; } }
Bye.