none
protect custom file being deleted exist in word package when user edit and save the word document. RRS feed

  • Question

  • Hi

    I am using System.IO.Package to create a item1.xml file in word document.

    //code for creating item1.xml

       using (Package package = Package.Open(fullDocumentPath, FileMode.Open,
                   FileAccess.ReadWrite))
                    {
                        Uri uriPartTarget = new Uri("/customXml/item1.xml", UriKind.Relative);


                        if (!package.PartExists(uriPartTarget))
                        {
                            PackagePart customXml = package.CreatePart(uriPartTarget,
                                "application/vnd.openxmlformats-officedocument.customXmlProperties+xml");

                        }

                   }

    But After creation if I edit and save word document then item1.xml got deleted.so is there any solution to protect item1.xml file?

    Tuesday, April 2, 2013 10:48 AM

Answers

  • Hi Cindy

    Thanks for asking but I found my solution

    here is the answer

    PackagePart mainDocPart = package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
                                mainDocPart.CreateRelationship(newuriPartTarget, TargetMode.Internal, "Http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");

    this will create the relation between custom xml part and main document so that the custom file was not deleted on edit and save word document

    Wednesday, April 3, 2013 11:14 AM

All replies

  • Could you please provide more information about what you're trying to store in this xml file?

    Is it possible that what you need is a CustomXMLPart, instead?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, April 2, 2013 3:27 PM
    Moderator
  • Hi Cindy

    Thanks for asking but I found my solution

    here is the answer

    PackagePart mainDocPart = package.GetPart(new Uri("/word/document.xml", UriKind.Relative));
                                mainDocPart.CreateRelationship(newuriPartTarget, TargetMode.Internal, "Http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");

    this will create the relation between custom xml part and main document so that the custom file was not deleted on edit and save word document

    Wednesday, April 3, 2013 11:14 AM