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

Free Support Forum - aspose.com

How to insert the field comment

hi,

i can't insert the comment field in my document:

builder.InsertField("Comments", "");

i'cant see my comment in my document

Thanks

Hi there,

You can insert a comment field into the document using the code below:

Document doc = new Document("Document.doc");

DocumentBuilder builder = new DocumentBuilder(doc);

// Create a Comment.

Comment comment = new Comment(doc);

// Insert some text into the comment.

Paragraph commentParagraph = new Paragraph(doc);

commentParagraph.AppendChild(new Run(doc, "Comment text"));

comment.AppendChild(commentParagraph);

// Create CommentRangeStart and CommentRangeEnd.

int commentId = 0;

CommentRangeStart start = new CommentRangeStart(doc, commentId);

CommentRangeEnd end = new CommentRangeEnd(doc, commentId);

//Insert some text into the document.

builder.Write("This is text before the comment ");

// Insert comment and comment range start.

builder.InsertNode(comment);

builder.InsertNode(start);

// Insert some more text.

builder.Write("This is commented text ");

// Insert end of comment range.

builder.InsertNode(end);

// And finaly insert some more text.

builder.Write("This is text after the comment");

doc.Save("Document Out.doc");

If you need any further help please feel free to ask.

Thanks,

thank you four your answer, but my problem is that i want to insert the content of my document COMMENTS field not create a new comment and insert them.

when i execute this code,

builder.InsertField("COMMENTS", "");

doc.UpdateFields();

i see a {COMMENTS} in my doc when i Alt F9 but with no value, but with a right click update fields i can see my the value.

My probleme how to update field programmaticly

Thanks

Hi there,

Thank you for this additional information.

Do you mean you want insert your own text into the document property "comments". You can achieve this using the code below

doc.BuiltInDocumentProperties.Comments = "Comment";

Thanks,

Thank you for your replay.

i want to display the value of the property "COMMENTS" in the footer. if i do doc.BuiltInDocumentProperties.comments and i change the value of this property (by right click my word document and change the Comment value for exemple) , in my footer i can't see the new value automaticlly.

did you mean my problem?

Hi there,

Thank you for this additional information.The best way to have the document properties updating automatically in the document is to insert the DocumentProperty field by using the code below.

Document doc = new Document("Document.doc");

builder.InsertField("DOCPROPERTY Comments");

doc.UpdateFields();

doc.Save("Document out.doc");

If you change the document properties by invoking changes in code such as doc.BuiltInDocumentProperties.Comments = "Comment changed"; then these changes will be updated in the field after using doc.UpdateFields();

However if the changes are being made to document by changing the document properties through explorer while it has already been loaded into memory (after using Document doc = new Document("Document.doc");) then these changes will not be updated as the document has already loaded into memory. To update these changes into the currently loaded document you can use the code below.

Document doc = new Document("Document.doc");

//Code done here, document properties changed through explorer

Document tempDoc = new Document("Document.doc");

doc.BuiltInDocumentProperties.Comments = tempDoc.BuiltInDocumentProperties.Comments;

doc.UpdateFields();

doc.Save("Document out.doc");

Thanks,