Ribbon not showing up with dynamically generated ribbon XML from the database

Posted by ydobonmai on Stack Overflow See other posts from Stack Overflow or by ydobonmai
Published on 2010-12-26T12:48:05Z Indexed on 2010/12/26 12:54 UTC
Read the original article Hit count: 267

Filed under:
|
|

I am trying to form ribbon XML with the data from the database and following is what I wrote:-

  XNamespace xNameSpace = "http://schemas.microsoft.com/office/2006/01/customui";
  XDocument document = new XDocument();
  document.Add( new XElement (xNameSpace+"customUI"
                , new XElement("ribbon"
                , new XElement("tabs"))));
  // more code to add the groups and the controls with-in the groups
  .......
  // code below to add ribbon XML to the document and to add the relationship
   RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
   ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(ribbonXml.ToString());

   myDoc.CreateRelationshipToPart(ribbonExtensibilityPart); 

I don't see any error executing the above. However, when I open the changed document, I dont see my ribbon added. I see following in the CustomUI/CustomUI.xml inside the word:-

<?xml version="1.0" encoding="utf-8"?><customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon xmlns="">
    <tabs>
.....

I am not sure how the "xmlns" attribute is getting added to the ribbon element. When I remove that attribute, the ribbon gets showed.

Could anybody throw any idea on where am I going wrong?

© Stack Overflow or respective owner

Related posts about openxml

Related posts about ribbon