News Category

How to update Ask Field in C#

2016-12-28 08:08:25 Written by  support iceblue
Rate this item
(0 votes)

With Spire.Doc for .NET, developers can easily operate the word fields from code. We have already shown how to create an IF field and remove Custom Property Fields in C#. From Spire.Doc V5.8.33, our developers add a new event UpdateFields to handle the Ask Field. This article will focus on demonstrating how to update the ASK field on the word document in C#.

Firstly, please view the sample document with an Ask filed which will be updated later:

How to update Ask Field in C#

Step 1: Create a new instance of Spire.Doc.Document class and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx");

Step 2: Call UpdateFieldsHandler event to update the ASK field.

doc.UpdateFields += new UpdateFieldsHandler(doc_UpdateFields);

Step 3: Update the fields in the document.

doc.IsUpdateFields = true;

Step 4: Save the document to file.

doc.SaveToFile("output.docx", FileFormat.Docx);

The following doc_UpdateFields () method shows how to update the ask field:

private static void doc_UpdateFields(object sender, IFieldsEventArgs args)
 {
     if (args is AskFieldEventArgs)
     {
         AskFieldEventArgs askArgs = args as AskFieldEventArgs;

         askArgs.ResponseText = "Female";
     }
 }

Effective screenshot after updating the Ask Field in C#:

How to update Ask Field in C#

Full codes:

using Spire.Doc;
using Spire.Doc.Fields;
namespace Askfield
{
    class Program
    {
        public void Field()
        {

            Document doc = new Document();
            doc.LoadFromFile("Sample.docx");

            doc.UpdateFields += new UpdateFieldsHandler(doc_UpdateFields);

            doc.IsUpdateFields = true;

            doc.SaveToFile("output.docx", FileFormat.Docx);

        }
        private static void doc_UpdateFields(object sender, IFieldsEventArgs args)
        {
            if (args is AskFieldEventArgs)
            {
                AskFieldEventArgs askArgs = args as AskFieldEventArgs;

                askArgs.ResponseText = "Female";
            }
        }


    }
}

Additional Info

  • tutorial_title: Update Ask Field in C#
Last modified on Friday, 03 September 2021 03:29