I have one .docx file and Dictionary<string,string>
. I need to go through the document, and replace the text eqaul to Dictionary.Key
to its according value in Dictionary
. It will be on server, because of that I don't want to use Microsoft.Office.Interopt
library which generates COM objects. For the solution i prefered OpenXML
, but on web for me there is no working solution for it. I found this solution of Eric White . It didn't work for me. Exactly to say, I run method SearchAndReplace
but there is no changes in document. I went through the methods, and found the problem was in method PutXmlInDocument
method, which saves XmlDocument
to given OpenXmlPart
by getting stream of it. Is there any other solutions with using OpenXML
or what to do save XmlDocument
to OpenXmlPart
?
It is that method which saving was unsuccessful :
public static void PutXmlDocument(OpenXmlPart part, XmlDocument xmlDoc)
{
using (Stream partStream = part.GetStream(FileMode.Create, FileAccess.Write))
using (XmlWriter partXmlWriter = XmlWriter.Create(partStream))
xmlDoc.Save(partXmlWriter);
}