If the CustomProperty changed, does the docx file changes too?

Jun 8, 2010 at 4:33 PM

If I open a docx file using DocX and then change the CustomProperty by using AddCustomProperty method.  If there are some DocProperty field defined in the document, does all the text be changed after docx file saved?  If not, how to apply these changes to reflect to the document?


Jun 8, 2010 at 11:49 PM
Hi doggy8088,

the following piece of code does what you want.

// Load a document.
using (DocX document = DocX.Load(@"Test.docx"))
    // Update or Add the custom property Name.
    document.AddCustomProperty(new CustomProperty("Name", "doggy8088"));
    // Save all changes made to this document.

This is what the input file looks like (Test.docx)

Here is the output of running the above code (Test2.docx)


As you can see the field values are auto updated.

kind regards,
Jun 9, 2010 at 1:29 AM

Hi coffeycathal,

Although I can't see your screenshot, but I understand what you said.  I'll take a try on it.  Thanks! 

By the way, I know your AddCustomProperty will remove the current CustomProperty and insert a new one into document.  I would like to recommand you to use SetCustomProperty or InsertCustomProperty as the method name to avoid ambiguous meaning.
For example, in the .NET 1.1, the Cache.Add will cause exception when key has been already exists and Cache.Insert will just replace it.

It will be better if you can support document.CustomProperty["Name"] = "doggy8088"; to insert or replace a CustomProperty.

I think DocX is a very good project.  You did a good job.  Thanks!

best regards,

Mar 9, 2011 at 7:43 AM
Edited Mar 9, 2011 at 9:12 AM

If the custom property is inside a table, the change does not reflect (the change has to be manually updated) to the document. Is it a bug?