need to replace formfield in word file with different other formfield types(like HTML, image, hyperlink).
Ok. Thanks for your reply.
Hello,
I am using below code for adding new form fields and remove old one.
but for second time, it will give me the error like
“System.InvalidOperationException: Document structure was changed.”.
please see below code,
foreach (Aspose.Words.Fields.FormField field in doc.Range.FormFields)
{
if (field.Type == Aspose.Words.Fields.FieldType.FieldFormTextInput)
{
if (field.Name == "xxDWPerPremLmtLab_1")
{
Node currentNode = field;
while (currentNode.NodeType != NodeType.FieldStart)
{
currentNode = currentNode.PreviousSibling;
}
//move cursor to fieldStrar
builder.MoveTo(currentNode);
//Insert image
builder.InsertImage(FilePath + "test.jpg");
//Now we should remove field
while (currentNode.NodeType != NodeType.FieldEnd)
{
currentNode = currentNode.NextSibling;
currentNode.PreviousSibling.Remove();
}
//currentNode.Remove();
doc.UpdateFields();
doc.Save(FilePath + FileName);
}
}
}
please let me know, the solution ASAP.
Hi Saurabh,
Hi Saurabh,
Thanks for sharing the document. Please use the following code example to get the desired output. Hope this helps you.
Document doc = new Document(MyDir + "test.rtf");
DocumentBuilder builder = new DocumentBuilder(doc);
foreach (FormField formfield in doc.Range.Bookmarks["xxDWPerPremLmtLab_1"].BookmarkStart.ParentNode.Range.FormFields)
{
if (formfield.Name == "xxDWPerPremLmtLab_1")
{
doc.Range.Bookmarks["xxDWPerPremLmtLab_1"].Text = "";
builder.MoveToBookmark("xxDWPerPremLmtLab_1");
builder.InsertTextInput("TextInput", TextFormFieldType.Regular, "", "Hello", 0);
break;
}
}
doc.Save(MyDir + "17.5.docx");