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);
}
}
}
| |