Aspose Words Form Fields

Hi,

I have a textbox, dropdownlist, checkbox and combobox on my word document. Can you please send me a sample to read the values of these form fields and also how to change the values from the code in C#.

Is there a way I can get the selected index of the combo/dropdown list control?

Thank you for your help!!

Siva

Hi Siva,

Thanks for your inquiry. Sure, you can interact with content controls by using StructuredDocumentTag class. Here is the code to insert plain text and select the Drop Down List item from the content control:

Document doc = new
Document(@"C:\Temp\SDTs.docx");

foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (sdt.SdtType == SdtType.PlainText)
    {
        sdt.RemoveAllChildren();
        Paragraph para = sdt.AppendChild(new Paragraph(doc)) as Paragraph;
        Run run = new Run(doc, "new text goes here");
        para.AppendChild(run);
    }
    else if (sdt.SdtType == SdtType.DropDownList)
    {
        SdtListItem secondItem = sdt.ListItems[2];
        sdt.ListItems.SelectedValue = secondItem;
    }
}

doc.Save(@"C:\temp\out.docx");

I hope, this will help.

Moreover, could you please attach your Word document that contains the CheckBox/ComboBox Controls? I will closely look into it and provide you code snippet.

Best regards,

Hi Hafeez,
Thank you very much for your quick and prompt reply.

Here is my code. Our document will be protected and will only allow to fill form fields.

Please let me know if the below code will always get all the form fields on the word document from multiple pages. Please let me know if there is any page limit for word document if I use below code. A sample document is attached.

Document doc1 = new Document("c:\temp\Sample_1.docx");
NodeList formFields = doc1.SelectNodes("//FormField");

// Traverse the list
foreach (Aspose.Words.Fields.FormField ffield in formFields)
{
    switch (ffield.Type) // ffield.Type.ToString()
    {
	case Aspose.Words.Fields.FieldType.FieldFormCheckBox: //"FieldFormCheckBox":
	    // Do something
	    break;
	case Aspose.Words.Fields.FieldType.FieldFormTextInput: // "FieldFormTextBox":
	    // Do something
	    break;
	case Aspose.Words.Fields.FieldType.FieldFormDropDown: //"FieldFormDropDown":
	    // Do something
	    break;
    }
}

Hi Siva,


Thanks for your inquiry. There is no limit of pages in the document. You can load a document with any number of pages in it using Aspose.Words. The only limit is amount of RAM on your side. Secondly, yes, you can get a reference to Form Fields using the code you posted in previous post. If we can help you with anything else, please feel free to ask.

Best regards,

A post was split to a new topic: Combine document with different protection type