Using RetrieveEntityRibbonRequest to get the ribbon definition of an Entity


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;


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.