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

Free Support Forum - aspose.com

Custom Document Properties (Yes/No Field)

I am setting custom document properties for a property that has a type of Yes/No.

Why does this command not work? It is setting it properly in code, but does not take in the Word document. Using C#

Document doc = new Document(templateFilePath);

doc.CustomDocumentProperties["~IsStrong"].Value = true;

Thanks

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. I tested this on my side and it seems all works fine. I used the same code as you use.

Document doc = new Document(@"Test064\in.doc");

doc.CustomDocumentProperties["test"].Value = false;

doc.Range.UpdateFields();

doc.Save(@"Test064\out.doc");

Maybe you also should update fields (see highlighted line).

Also please attach your document for testing.

Best regards.

I do have a doc.Range.UpdateFields(); command.

In this code, the document is created with custom document properties IsNew, IsNew2 and IsNew3.

When I examine the actual document, the custom document properties has: IsNew = No; IsNew2=Yes; IsNew3=Yes; The only difference, is that IsNew was an existing document property before the Clear command. The .Remove command does not help.

Code

doc.CustomDocumentProperties.Remove("~IsNew");

doc.CustomDocumentProperties.Clear();

doc.Range.UpdateFields();

doc.CustomDocumentProperties.Add("~IsNew", true);

doc.CustomDocumentProperties.Add("~IsNew2", true);

doc.CustomDocumentProperties.Add("~IsNew3", true);

doc.CustomDocumentProperties["~IsNew"].Value = true;

doc.Range.UpdateFields();

doc.Save(Program.inProgressDir + jobDetail.documentSaveName, SaveFormat.Doc);

Here is a sample document for testing

Sorry, please use this document instead

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I still can’t reproduce this issue. Here is code ia used for testing.

Document doc = new Document(@"Test064\LR+LB+ft+0815-019_LB(13357).doc");

doc.CustomDocumentProperties.Add("~IsNew2", true);

doc.CustomDocumentProperties.Add("~IsNew3", true);

doc.CustomDocumentProperties["~IsNew"].Value = true;

doc.Range.UpdateFields();

doc.Save(@"Test064\out.doc");

In the output document I get the expected result - IsNew = Yes; IsNew2=Yes; IsNew3=Yes.

Please make sure you are using the latest version of Aspose.Words. I use 5.2.2 version for testing.

Best regards.

I was using 5.1.1. Updated to 5.2.2. Same problem.

Then I discovered that there is a Word Macro that is setting "~IsNew" to false when the document is closed. Problem solved. Sorry to put you thru this problem. A bit embarrassed. Regards,

It is nice that all works fine now. :-)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Best regards.