Welcome to OpenXML Developer Sign in | Join | Help

How to add customXML part to docx (opened to Stream from WebClient) using OpenXML sdk

Last post 07-29-2008, 12:13 PM by wpaven. 1 replies.
Sort Posts: Previous Next
  •  07-16-2008, 8:43 PM 3475

    How to add customXML part to docx (opened to Stream from WebClient) using OpenXML sdk

    Hi all,
     I posted this yesterday on the msdn forums and they suggested I post here instead:

    I have a Word .docx saved in a webDAV folder on my client.  I want to open the file and add a customXML piece, I'm running the following code, but keep getting the error:

       "Cannot open package because FileMode or FileAccess value is not valid for the stream."

    I can download the file to a tmp dir, and then open the document from the filesystem and add the piece, but I'd like to be able to do this just using the file in the webDAV folder, opened from a Stream.

    any suggestions please?

    public static void AddNewPart(string fileName)  //filename is just the path+filename of customxml piece.

    {

        WebClient Client = new WebClient();

        Client.Credentials = new System.Net.NetworkCredential("user","pwd");

        Stream strm = Client.OpenRead("http://localhost:8008/sdkTest1.docx");

     

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(strm, true))

        { 

           MainDocumentPart mainPart = wordDoc.MainDocumentPart;

           CustomXmlPart myXmlPart = mainPart.AddNewPart<CustomXmlPart>();

             using (FileStream stream = new FileStream(fileName, FileMode.Open))

             {

                 myXmlPart.FeedData(stream);

             }

        }

    }

  •  07-29-2008, 12:13 PM 3509 in reply to 3475

    Re: How to add customXML part to docx (opened to Stream from WebClient) using OpenXML sdk

    For those who might find it useful, the answer to this can be found at :

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3679755&SiteID=1&mode=1




View as RSS news feed in XML