匯出功能區定義
發行︰ 2016年11月
適用於: Dynamics CRM 2015
要有效定義預設 RibbonXml 的變更,您必須參照定義這些功能區的 RibbonXml 資料。
存取組織的功能區定義
如果修改組織的功能區,如果想要使用自訂功能區的元素,您應該匯出目前定義。 若要這樣做,請使用位於 SampleCode\CS\Client\Ribbon\ExportRibbonXml 的 exportribbonxml 範例檔案。
存取預設的功能區資料
Microsoft Dynamics 365 的預設的功能區定義可以在 SDK 套件找到:SDK\Resources\ExportedRibbonXml。下載 Microsoft Dynamics CRM SDK 套件。
applicationRibbon.xml 檔案包含核心應用程式功能區定義。
剩餘檔案包含的功能區定義與使用實體範本不同的實體的定義。 每個檔案根據實體名稱命名:邏輯實體名稱 + Ribbon.xml。
此檔案代表輸出兩個訊息,使用了 範例:匯出功能區定義:
RetrieveApplicationRibbonRequest
此訊息擷取核心應用程式功能區,包含實體範本。RetrieveEntityRibbonRequest
此訊息擷取用於特定實體的功能區定義。
解壓縮功能區資料
功能區資料匯出成壓縮檔。 若要解壓縮檔案至 XML,您必須使用 System.IO.Packaging.ZipPackage 類別。 下列範例是一種用在 SDK 範例來解壓縮檔案的 Helper 方法。
/// <summary>
/// A helper method that decompresses the the Ribbon data returned
/// </summary>
/// <param name="data">The compressed ribbon data</param>
/// <returns></returns>
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;
}
}
''' <summary>
''' A helper method that decompresses the the Ribbon data returned
''' </summary>
''' <param name="data">The compressed ribbon data</param>
''' <returns></returns>
Public Function unzipRibbon(ByVal data() As Byte) As Byte()
Dim package As System.IO.Packaging.ZipPackage = Nothing
Dim memStream As MemoryStream = Nothing
memStream = New MemoryStream()
memStream.Write(data, 0, data.Length)
package = CType(ZipPackage.Open(memStream, FileMode.Open), ZipPackage)
Dim part As ZipPackagePart = CType(package.GetPart(New Uri("/RibbonXml.xml", UriKind.Relative)), ZipPackagePart)
Using strm As Stream = part.GetStream()
Dim len As Long = strm.Length
Dim buff(CInt(len - 1)) As Byte
strm.Read(buff, 0, CInt(len))
Return buff
End Using
End Function
擷取應用程式功能區資料
如下列範例所示,應用程式功能區可以使用 RetrieveApplicationRibbonRequest 擷取。
//Retrieve the Appliation Ribbon
RetrieveApplicationRibbonRequest appribReq = new RetrieveApplicationRibbonRequest();
RetrieveApplicationRibbonResponse appribResp = (RetrieveApplicationRibbonResponse)_serviceProxy.Execute(appribReq);
System.String applicationRibbonPath = Path.GetFullPath(exportFolder + "\\applicationRibbon.xml");
File.WriteAllBytes(applicationRibbonPath, unzipRibbon(appribResp.CompressedApplicationRibbonXml));
'Retrieve the Appliation Ribbon
Dim appribReq As New RetrieveApplicationRibbonRequest()
Dim appribResp As RetrieveApplicationRibbonResponse = CType(_serviceProxy.Execute(appribReq), RetrieveApplicationRibbonResponse)
Dim applicationRibbonPath As String = Path.GetFullPath(exportFolder & "\applicationRibbon.xml")
File.WriteAllBytes(applicationRibbonPath, unzipRibbon(appribResp.CompressedApplicationRibbonXml))
擷取實體功能區
若要擷取實體功能區定義,您可以包括實體名稱為參數至 RetrieveEntityRibbonRequest。
若要為所有支援功能區的實體擷取功能區定義,您需要一份具有功能區定義 (變更實體功能區範本) 的系統實體清單。 下列範例顯示所有具備功能區定義的系統實體陣列。
//This array contains all of the system entities that use the ribbon.
public System.String[] entitiesWithRibbons = {"account",
"activitymimeattachment",
"activitypointer",
"appointment",
"bulkoperation",
"calendar",
"campaign",
"campaignactivity",
"campaignresponse",
"competitor",
"connection",
"contact",
"contract",
"contractdetail",
"convertrule",
"convertruleitem",
"customeraddress",
"discount",
"discounttype",
"email",
"emailserverprofile",
"entitlement",
"entitlementchannel",
"entitlementtemplate",
"entitlementtemplatechannel",
"fax",
"goal",
"goalrollupquery",
"importfile",
"incident",
"invoice",
"invoicedetail",
"kbarticle",
"kbarticlecomment",
"lead",
"letter",
"list",
"listmember",
"mailbox",
"metric",
"opportunity",
"opportunityproduct",
"partnerapplication",
"phonecall",
"postfollow",
"pricelevel",
"product",
"productpricelevel",
"queue",
"queueitem",
"quote",
"quotedetail",
"recurringappointmentmaster",
"report",
"rollupfield",
"routingrule",
"routingruleitem",
"salesliterature",
"salesliteratureitem",
"salesorder",
"salesorderdetail",
"service",
"serviceappointment",
"sharepointdocument",
"sharepointdocumentlocation",
"sharepointsite",
"site",
"sla",
"slaitem",
"socialactivity",
"socialprofile",
"systemuser",
"task",
"team",
"teamtemplate",
"territory",
"uom",
"uomschedule",
"userquery"};
'This array contains all of the system entities that use the ribbon.
Public entitiesWithRibbons() As String = {"account", "activitymimeattachment", "activitypointer", "appointment", "bulkoperation", _
"campaign", "campaignactivity", "campaignresponse", "competitor", "connection", "contact", _
"contract", "contractdetail", "customeraddress", "discount", "discounttype", "email", "fax", "goal", _
"importfile", "incident", "invoice", "invoicedetail", "kbarticle", "kbarticlecomment", "lead", _
"letter", "list", "listmember", "metric", "opportunity", "opportunityproduct", "phonecall", _
"pricelevel", "product", "productpricelevel", "queueitem", "quote", "quotedetail", _
"recurringappointmentmaster", "report", "salesliterature", "salesorder", "salesorderdetail", _
"service", "serviceappointment", "sharepointdocumentlocation", "sharepointsite", "systemuser", _
"task", "team", "territory", "uom", "uomschedule", "userquery"}
下列範例顯示如何擷取一組功能區定義實體。
//Retrieve system Entity Ribbons
RetrieveEntityRibbonRequest entRibReq = new RetrieveEntityRibbonRequest() { RibbonLocationFilter = RibbonLocationFilters.All };
foreach (System.String entityName in entitiesWithRibbons)
{
entRibReq.EntityName = entityName;
RetrieveEntityRibbonResponse entRibResp = (RetrieveEntityRibbonResponse)_serviceProxy.Execute(entRibReq);
System.String entityRibbonPath = Path.GetFullPath(exportFolder + "\\" + entityName + "Ribbon.xml");
File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml));
//Write the path where the file has been saved.
Console.WriteLine(entityRibbonPath);
}
'Retrieve system Entity Ribbons
Dim entRibReq As New RetrieveEntityRibbonRequest() With {.RibbonLocationFilter = RibbonLocationFilters.All}
For Each entityName As String In entitiesWithRibbons
entRibReq.EntityName = entityName
Dim entRibResp As RetrieveEntityRibbonResponse = CType(_serviceProxy.Execute(entRibReq), RetrieveEntityRibbonResponse)
Dim entityRibbonPath As String = Path.GetFullPath(exportFolder & "\" & entityName & "Ribbon.xml")
File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml))
'Write the path where the file has been saved.
Console.WriteLine(entityRibbonPath)
Next entityName
所有自訂實體也支援功能區自訂。 若要取得自訂實體清單,請使用 RetrieveAllEntitiesRequest 並擷取自訂實體名稱。 下列範例顯示如何擷取所有自訂實體的功能區定義。
//Check for custom entities
RetrieveAllEntitiesRequest raer = new RetrieveAllEntitiesRequest() { EntityFilters = EntityFilters.Entity };
RetrieveAllEntitiesResponse resp = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(raer);
foreach (EntityMetadata em in resp.EntityMetadata)
{
if (em.IsCustomEntity == true && em.IsIntersect == false)
{
entRibReq.EntityName = em.LogicalName;
RetrieveEntityRibbonResponse entRibResp = (RetrieveEntityRibbonResponse)_serviceProxy.Execute(entRibReq);
System.String entityRibbonPath = Path.GetFullPath(exportFolder + "\\" + em.LogicalName + "Ribbon.xml");
File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml));
//Write the path where the file has been saved.
Console.WriteLine(entityRibbonPath);
}
}
}
'Check for custom entities
Dim raer As New RetrieveAllEntitiesRequest() With {.EntityFilters = EntityFilters.Entity}
Dim resp As RetrieveAllEntitiesResponse = CType(_serviceProxy.Execute(raer), RetrieveAllEntitiesResponse)
For Each em As EntityMetadata In resp.EntityMetadata
If em.IsCustomEntity = True AndAlso em.IsIntersect = False Then
entRibReq.EntityName = em.LogicalName
Dim entRibResp As RetrieveEntityRibbonResponse = CType(_serviceProxy.Execute(entRibReq), RetrieveEntityRibbonResponse)
Dim entityRibbonPath As String = Path.GetFullPath(exportFolder & "\" & em.LogicalName & "Ribbon.xml")
File.WriteAllBytes(entityRibbonPath, unzipRibbon(entRibResp.CompressedEntityXml))
'Write the path where the file has been saved.
Console.WriteLine(entityRibbonPath)
End If
Next em
End Using
另請參閱
自訂命令和功能區
命令列或功能區簡介
匯出,準備編輯,然後匯入功能區
© 2017 Microsoft. 著作權所有,並保留一切權利。 著作權