We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

A corrupted file when i insert a DOCPROPERTU in the footer of the section

Hi,

i have a corrupted DOCX file when i insert a DOCPROPERTY COMMENTS in the footer of the section with this code:

Document doc = new Document(fileStream1);

DocumentBuilder builder = new DocumentBuilder(doc);

foreach (Section sec in doc.Sections)

{

builder.MoveToSection(doc.IndexOf(sec));

builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);

builder.InsertField("DOCPROPERTY COMMENTS");

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

builder.InsertField("DOCPROPERTY COMMENTS");

}

doc.UpdateFields();

doc.UpdatePageLayout();

doc.Save(fileStream1, SaveFormat.Docx);

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Could you please also attach your input and output documents here for testing? I will check them and provide you more information.

Best regards.

thank you for you post.

do you find in the input and output files

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. The problem occurs because you save the document into the stream, which already contains the original document. When you open document from stream, Aspose.Words reads the stream to the end, so after reading position of the stream is at the end of the stream. When you save document to stream Aspose.Words writes document’s content into the stream starting from the current position. So your output stream actually contains both input and output documents.

The solution is very simple, just save the document into another stream.

Best regards.