i'm trying to do changes on a word document using DocumentFormat.OpenXml, ive tried even looking the following question: Save modified WordprocessingDocument to new file but i cant find a way to save the change to same file.
Tried the below but the file didn't change.
public static void WriteToWordDoc(string filepath)
{
using (WordprocessingDocument wordprocessingDocument =
WordprocessingDocument.Open(filepath, true))
{
Body body = wordprocessingDocument.MainDocumentPart.Document.Body;
var old = body.InnerXml.ToString();
var sdtCont = body.InnerXml.Replace("Hello", "Hi");
wordprocessingDocument.MainDocumentPart.Document.Save();
wordprocessingDocument.Close();
}
}
Please assist.