SetCustomProperty method not found!

Jul 16, 2009 at 10:56 PM

Hi again Cathal!

Object Explorer & IntelliSense don't show any "SetCustomProperty" occurrence at all (not in DocX Class neither in CustomProperty Class).

I'm using v1.0.0.5, downloaded from here (CodePlex)

I need set the Value for a Custom made property on a .docx files, as you explain in your last home's web page project example.

Thanks in advance!

Gaspar

Coordinator
Jul 17, 2009 at 8:47 AM
Hi Gaspar,

I do not update my past blog posts when the syntax of DocX changes.
Instead I make sure that the documentation.chm file is always up to
date. It can be downloaded from
http://docx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29595#DownloadId=73650
and it contains 2 examples of how to use the method
AddCustomProperty(). In order to read the documentation (Windows
dosen't trust .chm files) you need to following the steps outline here
http://cathalscorner.spaces.live.com/. I have pasted one of these
examples below for you.

By the way, thank you for your kind review of DocX 1.0.0.5. It put a
huge smile on my face.
Let me know if I can help anymore,
kind regards,
Cathal

// Load Example.docx
using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
{
// A CustomProperty called forename which stores a string.
CustomProperty forename;

// If this document does not contain a custom property called
'forename', create one.
if (!document.CustomProperties.ContainsKey("forename"))
{
// Create a new custom property called 'forename' and set its value.
document.AddCustomProperty(new CustomProperty("forename", "Cathal"));
}

// Get this documents custom property called 'forename'.
forename = document.CustomProperties["forename"];

// Print all of the information about this CustomProperty to Console.
Console.WriteLine(string.Format("Name: '{0}', Value: '{1}'\nPress
any key...", forename.Name, forename.Value));

// Save all changes made to this document.
document.Save();
} // Release this document from memory.

// Wait for the user to press a key before exiting.
Console.ReadKey();
Jul 17, 2009 at 2:21 PM

Cathal,

Thanks for the tip, I will test using "AddCustomProperty" right now.

By the way, looking at .chm documentation file, AddCustomProperty method page, there is a typo (or something similar):

The two examples provided are the same! :-P (both gets 'forename' Property value)

Cheers

Gaspar

Coordinator
Jul 20, 2009 at 11:58 AM
Gaspar,
 
Sorry again for the delay, you wrote.
 
>>By the way, looking at .chm documentation file, AddCustomProperty method page, there is a typo (or something similar):
>>The two examples provided are the same! :-P (both gets 'forename' Property value)
 
Thank you for spotting this, I will replace one of these examples with something more useful that a duplicate.
 
thanks again,
Cathal
Aug 12, 2009 at 12:16 PM

Hi,

I have already implemented a docx merging system using Content Controls bound to custom XML using the OpenXML SDK - however, after deploying this to the customer I have discovered that the Word 2003 docx support doesn't include binding these Content Controls to the XML values - so I am in urgent need of an alternative to this.

Your example on the home page of '4) Set custom properties' seemed like perfect solution to my problem.

However, downloading the latest release I couldn't see the SetCustomProperty on the docx object, then I found this thread.

I have a series of Word Template that I removed the Content Controls and replaced them with Custom Properties (as per your screenshots on the homepage).

I have tried the following code:

DocX doc = DocX.Load(fileName);
doc.AddCustomProperty(new CustomProperty("MyCustomProp", "MyValue"));
etc..
doc.Save();

Opening the document in Word 2007 doesn't show the new values in the Custom Property fields within the document.  However, opening the Template Properties dialog in Word shows my custom properties have had their values updated.

Any ideas how to get the the values in the word template to update?

Thanks,

Murray

 

Coordinator
Aug 12, 2009 at 12:30 PM
Hi muzfrancis,

thank you for your interest in DocX. I am sorry that I have not updated all of the code examples on my blog. I do however maintain a documentation.chm file which contains examples of how to use every DocX function. This is always up to date with the newest syntax and is available to download from http://docx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31072#DownloadId=77818.

I think i know what your problem is. Where in your document are the CustomProperties being displayed? The current version of DocX that is available on docx.codeplex.com only refreshes custom properties that are in the document's body.The next version that I am working on will update custom properties even if they are in the header, footer or inside another control such as a TextBox.

If this would solve your problem, I will compile and email you a copy of the next version, so that you can use it before it is available on docx.codeplex.com.
kind regards,
Cathal
Aug 12, 2009 at 1:47 PM

Hi,

Thanks for the prompt reply!

I have actually solved my immediate issue by still using my XML bound Content Controls, but also using your DocX ReplaceText() method to replace the placeholder text values within my content controls. So my existing solution works with Word 2007 still, and Word 2003 just shows the values replaced using your ReplaceText() method. 

I will keep an eye on this project and try the AddCustomProperty again when you release a new version.

Thanks again!

Murray

Sep 10, 2009 at 3:16 PM

Hello,

Does 1.0.0.8 fix this issue?  I'm using this version, but I still don't see the fields being updated.

Thanks,

Matt

Coordinator
Sep 10, 2009 at 4:30 PM
Hi Matt,

In my attempts I cannot recreate the problem that you are experiencing. When I use AddCustomProperty with a property name that already exists, all instances of that CustomProperty have their value updated to the new value.

Can you please send me the document that is causing you this problem? I will then try and debug this issue and fix it for you.

kind regards,
Cathal
Oct 29, 2009 at 1:38 PM

Hi Cathal,

Can you provide a code snippet of how to update custom properties for content controls that are in the header, footer parts?

Thanks,

Satchi