Writing custom document properties


Do you have code examples showing how to write to custom document properties? I can see this option is available in corporate edition. Besides I’d like to know how to update custom document properties in the document (something similar to “print preview” or “Update field”).

Best regards



To add custom document properties:

Document doc = TestUtil.Open(@“TestDocProperties.doc”);
doc.CustomDocumentProperties.Add(“AddedProperty1”, “blah blah”);
doc.CustomDocumentProperties.Add(“AddedProperty2”, 321);

To modify existing:
dstDoc.CustomDocumentProperties[“MyDate”].Value = new DateTime(2004, 6, 18);

You can add, remove and enumerate properties.

Document class has CustomDocumentProperties and BuiltinDocumentProperties collection which contain DocumentProperty objects - very similar to MS Word automation interface.


Thanks for your reply. It works just fine. But how can I update the custom field which is inserted in the word document? In MS Word document you can right-click on the “grey” field and select “Update field”. (“Print preview” function does just the same. ) Then you update the text in the fields with the property value. How can I do it in the code with aspose.word?

With best regards


Aspose.Word is just an engine to open, modify and save Word documents. What you are asking for does not seem like a function that Aspose.Word supports at the moment.

Please explain why do you need to do this, what sort of task do you have? We will come up with some idea then.


Hi again,
I have an application which looks like this: I have a database. I have also an intranet page which provides user interface for adding and editing records in the databse. Each record in the database has its own word document (a kind of a report) which belongs only to this record. Each time the user changes something in the database (via web interface) my application has to update the word document which belongs to this record. It can be done by updating document properties. When the user changes and saves the record in the database the application updates custom properties in the word document. The problem is that when the user opens the word document he cannot see thet the values of the fields have changed before he right-clicks on the grey fields to update them (or chooses print preview). He can only see the old values when he opens the document. This can be confusing for the users because they think that the “automatic field update” does not work at all.
In good old ;o) VB the function I need would be like:
wdApp.ActiveDocument.PrintPreview, wdApp.ActiveDocument.ClosePrintPreview.
The function wdApp.ActiveDocument.Fields.Update does work too but it does not update header and footer…and I have custom property fields in header and footer too.



Currently Aspose.Word does not have an engine to update values of existing fields in the document. Although this probably can be done for simple fields such as the ones that refer to custom document properties, it cannot be done for many other fields such as page numbers, TOC etc that require the document to be laid into pages before calculation.

I will note your request on our task list, but at this stage I cannot promise this feature will be supported.

In the meantime you can do this if that’s suitable:

1. Remove the fields from existing documents and insert bookmarks in their places instead.
2. Open the document in Aspose.Word, create a DocumentBuilder.
3. Use DocumentBuilder.MoveToBookmark to navigate to the place in the document and use DocumentBuilder.Write to insert the value you want.
4. You can even use DocumentBuilder.Font.Shading to set gray background or even more exciting formatting similar to what you currently have with the fields.


There is Range.UpdateFields methods available now.

It updates the values of document fields in a range, but at the moment only updates DOCPROPERTY and DOCVARIABLE fields.

Document.Range.UpdateFields() you can update fields in a whole document.