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

Free Support Forum - aspose.com

mobjAsposeDoc.Range.FormFields.Count Returning Zero

Hello,

I am using Aspose.Words to read the DOCM files attached and cannot get the mobjAsposeDoc.Range.FormFields.Count for the document. Can you please try loading attached document to Aspose.Words objects and try getting the mobjAsposeDoc.Range.FormFields.Count?

I am not sure why I am getting the value as 0(zero) all the time. When I open the same document in MSWord I do see that Form Fields exists.

Appreciate any help in this regard.

Thanks,

Vinay Hattarki

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Hi

Thanks for your inquiry. Your document does not contain Form Fields, but it contains Merge Field. Form Fields and Merge Fields are different things in MS Word.

If you need to get list of Merge Fields in your document, you can use code like the following:

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

string[] mergeFields = doc.MailMerge.GetFieldNames();

foreach (string field in mergeFields)

Console.WriteLine(field);

Also, please see the following link to learn how to execute mail merge using Aspose.Words:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/simple-mail-merge-explained.html

Best regards,

Thanks!!! That Helped.

I was now trying to assign the Merge Field Text in a loop.

I am using code loop provided by you and was trying to change the text in mergefild in a loop dynamically at run time. I dont see how we can create MergeField object as I dont see it under Aspose.Words.Fields namespace. How can I perform line 1 and 2 in loop below?

Dim lsMergeFields As String()

Dim lsField As String

For Each lsField In lsMergeFields

1-- Dim mergeField As New MergeField("NameofMergeField)

2-- mergeField.Text ="CHANGE DYNAMICALLY"

Next

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:SimSun; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Hi

Thanks for your request. Actually, merge fields are intended to be replaced with value. So you should use mail merge for fill the document with data as I already suggested in my previous answer:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/simple-mail-merge-explained.html

When you execute Mail Merge, merge fields are replaced with the corresponding values in your data source,

Best regards,