How to access form fields in WOrd

I have a big word document that already have form fields (text, checkbox, radio button) in it. I have a .NET application where users enter their responses and I need to write their responses into those form fields in the word documents. Is this possible with ASPOSE.Word application? How do I access/reference to a specific form field? with its bookmark property?

thanks

Yavuz


This message was posted using Aspose.Live 2 Forum

Hi

Thanks for your inquiry. You can achieve this using code like the following.

//Set value of TextBox form field
doc.Range.FormFields["GoodTextInput"].SetTextInputValue("test");
//Set value of ChekBox
doc.Range.FormFields["CheckBox"].Checked = false;

etc.

More information you can find here.
https://reference.aspose.com/words/net/aspose.words.fields/formfield/

Please let me know if you would like to know anything else.

Best regards.

what is “.Range” for? if I assign unique bookmarks to each texbox, checkbox, etc in the word document, can I just access to all with the code you provided without going through each control hierchary… in other words all doc.Range.FormFields will give me ALL the form fields no matter what parent structure they are nested in.

thanks,

Yavuz

Hello!

Range is an object representing a part of a document or the whole document (as in this case) as the sequence of elements. It is documented here:
https://reference.aspose.com/words/net/aspose.words/range/

Yes, doc.Range.FormFields collection includes all form fields in the document regardless of their location in the document structure. Just try using it. That’s very easy.

Regards,

ok I will try… another question:

after populating all the form fields in the word document, is it possible to make some controls read only/protected and some controls editable/unprotected programatically by using Aspose commands?

another question: when I am writing into a text form field in the Word document from .NET application, if the text is longer than the text field’s length, will the text form extend in the word document to the next row?

Sorry, this is not supported. But you can protect individual sections. Also it is planned to support editable regions. That could be the closest feature to your case. You can find useful info here:
https://forum.aspose.com/t/118060

Have a nice day,

Form fields have no size properties. So they are “rubber”, they are stretched when you put longer text to them.

Is there any way of grouping checkboxes so that they act like radiobutton group? In other words, Can I assign Yes to a checkbox and No to another one and I give the same ‘bookmark’ name to both and when I say something like doc.Range.FormFields[“BookmarkName”].CheckedValue = “Yes”;, it will check the checkbox with the Yes value?

thanks

Hello!

Thank you for your inquiry.

There are no radio buttons in MS Word so you have no such possibility without manual programming application logic. When one check box is selected you should deselect all the others that belong to the same logical group. In MS Word you can provide handlers triggered on check box events and handle this.

Regards,

hi,

I am using

doc.Range.FormFields['bookmark'].SetTextInputValue('test')

doc.Range is only getting the formfields in the first table in the document, but does not the other formfields in the other tables or pages… the document is almost 100 pages long!!! you TOLD me doc.Range would return me all the formfields and we paid for it and now it is not working. Am I supposed to loop 'Range’s in the document, how do I do that? if this does not work, we need our money back unfortunately…

I saved the licence file inside the project directory, was I supposed to do something else?

please help ASAP… I attached the document. for instance it reads the Date of On-Site Review texbox in the first table at page 2 but does not see the checkboxes in the second table (A. General Appearance and Security) thanks

thanks

Although I copied the license file, it still says

Evaluation Only. Created with Aspose.Words. Copyright 2003-2007 Aspose Pty Ltd.

This document was truncated here because it was created using Aspose.Words in Evaluation

where are the instructions for installing the license???

Hi

Please see the following links to learn how to apply license
https://docs.aspose.com/words/net/licensing/

Best regards.