You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated a customxml part (item1.xml), then saved the word document.
After saving the word file, I reviewed the customxml part (item1.xml) and noted that it did update correctly.
Opened the word doc and noted that the data in the xml gets pulled into the word document as expected.
Without saving the word doc, I unpacked the doc file and reviewed document.xml file and noted that it did NOT update with the updated customxml part.
If I perform a Save As and examine the file again, the document.xml file is updated.
Screenshots
If applicable, add screenshots to help explain your problem.
To Reproduce
// Please add a self-contained, minimum viable repro of the issue.
// If you require external resources, please provide a gist or GitHub repro
// An Xunit style test is preferred, but a console application would work too.
Using the latest version. 3.1.0 and .Net 8
Usingvar os =new OpenSettings
{MarkupCompatibilityProcessSettings=new MarkupCompatibilityProcessSettings(
MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2007)};
Steps to reproduce the behavior:
beginning of code:
//Word Doc - Decode the word doc from SharePoint. byte[]byteWordDoc= Convert.FromBase64String(strWordDocBase64);MemoryStreamstreamWordDoc=new MemoryStream();
streamWordDoc.Write(byteWordDoc,0, byteWordDoc.Length);//XML Filebyte[]byteXMlFile= Convert.FromBase64String(strXMLFileBase64);XElementxmlfile= XElement.Parse(System.Text.Encoding.UTF8.GetString(byteXMlFile));
streamWordDoc.Seek(0, SeekOrigin.Begin);//Get the custom part for index1.xmlforeach(CustomXmlPart part in wordDoc.MainDocumentPart.CustomXmlParts){if(part.Uri.OriginalString.IndexOf(strWordDocNamespace)!=-1){mainXMLPart=part;break;}}using(Streamstream= mainXMLPart.GetStream(FileMode.Create, FileAccess.Write)){using(XmlWriterpartXMLWriter= XmlWriter.Create(stream)){
xmlfile.Save(partXMLWriter);};}
streamWordDoc.Seek(0, SeekOrigin.Begin);
wordDoc.Save();
wordDoc.Dispose();//Convert to base64 and return as JSON payload.varwordDocBase64=new{ worddoc = Convert.ToBase64String(streamWordDoc2.ToArray())};
Observed behavior
See notes above.
Expected behavior
The document.xml to be updated.
Desktop (please complete the following information):
OS: Windows 11
Office version 16
.NET Target: 8
DocumentFormat.OpenXml Version: 3.1.0
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
@dbeaudoinl99, as it has been a while since you posted this issue, have you solved it in the meantime?
Here are some things I noted:
Firstly, you did not provide a "complete" repro. For example, I can't see how you open the WordprocessingDocument. I can only guess you open it on the streamWordDoc.
Secondly, the following lines of code do not look right:
If you've opened the wordDoc on the streamWordDoc stream, it does not make sense to reset its position before saving the document, which you also do not have to do if you've created the WordprocessingDocument instance correctly. Here is how this would look like if you need to work with the stream after having closed the WordprocessingDocument:
using(WordprocessingDocumentwordDoc= WordprocessingDocument.Open(streamWordDoc,true)){// Do what you need to do with the wordDoc and its parts.// However, altering the stream at this point might not be a good idea.}// At this point, the `wordDoc` will have been auto-saved and properly disposed (and closed),// so no need to call Save() and Dispose().// You can now continue working with the stream.
streamWordDoc.Seek(0, SeekOrigin.Begin);
Describe the bug
Screenshots
If applicable, add screenshots to help explain your problem.
To Reproduce
// Please add a self-contained, minimum viable repro of the issue.
// If you require external resources, please provide a gist or GitHub repro
// An Xunit style test is preferred, but a console application would work too.
Using the latest version. 3.1.0 and .Net 8
Steps to reproduce the behavior:
beginning of code:
Observed behavior
See notes above.
Expected behavior
The document.xml to be updated.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: