Welcome to OpenXML Developer Sign in | Join | Help

Getting a handle on item1.xml

Last post 07-21-2008, 10:20 PM by DocMemory. 2 replies.
Sort Posts: Previous Next
  •  07-21-2008, 5:13 PM 3493

    Getting a handle on item1.xml

    I don't know why but I am having the hardest time getting a handle on the /customXml/item1.xml file.
    I have set it up to make a copy of my template file. but everytime I try and use the Open XML format SDK I can't seem to get to it in order to replace the xml inside so that it will change the content controls that are linked to it. It is really driving me up the wall. Is there a good way to open it with the Open Xml SDK?
     What is the "accepted" way to do this?
  •  07-21-2008, 6:05 PM 3494 in reply to 3493

    Re: Getting a handle on item1.xml

    Try using the system.IO.Packaging namespace

    Quick example for replacing the Data with a data.xml file

     

    //Load in the XML

    XmlDataDocument myXmlDocument = new XmlDataDocument();

    myXmlDocument.Load(dataPath + "\\data.xml");

    //Open the File using the packaging API

    using (Package p = Package.Open(createdDocPath, FileMode.Open, FileAccess.ReadWrite))

    {

       Uri partUri = new Uri("/CustomXml/item1.xml", UriKind.Relative);

       PackagePart part = p.GetPart(partUri);

       //Overwrite the part with the new XML

       using (Stream s = part.GetStream(FileMode.Create))

       {

          myXmlDocument.Save(s);

       }

       p.Flush();

    }

  •  07-21-2008, 10:20 PM 3495 in reply to 3494

    Re: Getting a handle on item1.xml

    Thanks!
     I guess that is the best way as of now. I was just hoping there was a more direct way with either the CustomXmlPart from the sdk. Oh well, here's hoping it's in 2.0  and that drops soon. Still, the packaging one isn't too cumbersome. Thanks!
View as RSS news feed in XML