Updating only parts of the Comments fields, after changing the values

Good day,
I change the value of the field in the document, update all fields of type Comments. However, the new value is written to me only in part of the fields. Could you take a look at why it doesn’t prescribe it for everyone but only for some…

my code:

Document doct = new Document("..................................");
doct.BuiltInDocumentProperties.Comments = "TestTest";

for (int idx = doct.Range.Fields.Count - 1; idx >= 0; idx--)
    Field field = doct.Range.Fields[idx];
    if (field.Type == FieldType.FieldComments)

the result is that out of 126 fields, the value changes in 55…
Thanks for any advice.

@benestom Could you please attach your document here for testing? We will check the issue and provide you more information.

P099_3M.docx (613.9 KB)

the document is divided into sections, each header has a field

@benestom Thank you for addition information. In your document there are COMMETS fields that replaces the value set in the doc.BuiltInDocumentProperties.Comments:

So upon updating these fields, the value in the doc.BuiltInDocumentProperties.Comments is overridden. Please see the following link for more information:

You can reset new comment text in the COMMETS to avoid this:

Document doc = new Document(@"C:\Temp\in.docx");

doc.BuiltInDocumentProperties.Comments = "TestTest";

doc.Range.Fields.Where(f => f.Type == FieldType.FieldComments).Cast<FieldComments>().ToList()
    .ForEach(f => { f.Text = null; f.Update(); });


Thank you in advance for your reply. This works fine…

1 Like