Hi,
I want to replace all checkboxes in a document with StructuredDocumentTag checkboxes. Unfortunately these do not appear or do not appear at the desired position. How can I do this? The checkboxes can also be in the middle of a paragraph.
First attemp, new checkboxes are not displayed:
FormFieldCollection formFields = WordDoc.Range.FormFields;
foreach (FormField field in formFields)
{
if (field.Type == (FieldType)TypeToConvert)
{
if (field.Type == FieldType.FieldFormCheckBox)
{
StructuredDocumentTag SdtCheckBox = new StructuredDocumentTag(WordDoc, SdtType.Checkbox, MarkupLevel.Inline)
{
Checked = field.Checked,
Tag = !string.IsNullOrWhiteSpace(field.Name) ? field.Name : “”
};
SdtCheckBox.ContentsFont.Size = field.Font.Size;
SdtCheckBox.ContentsFont.Bold = field.Font.Bold;
field.ParentNode.InsertAfter(SdtCheckBox, field);
field.Remove();
}
}
}
Second try, builder inserts on wrong place:
FormFieldCollection formFields = WordDoc.Range.FormFields;
foreach (FormField field in formFields)
{
if (field.Type == (FieldType)TypeToConvert)
{
if (field.Type == FieldType.FieldFormCheckBox)
{
StructuredDocumentTag SdtCheckBox = new StructuredDocumentTag(WordDoc, SdtType.Checkbox, MarkupLevel.Inline)
{
Checked = field.Checked,
Tag = !string.IsNullOrWhiteSpace(field.Name) ? field.Name : “”
};
SdtCheckBox.ContentsFont.Size = field.Font.Size;
SdtCheckBox.ContentsFont.Bold = field.Font.Bold;
builder.MoveTo(field.ParentNode);
builder.InsertNode(SdtCheckBox);
field.Remove();
retVal = retVal == -1 ? 1 : retVal++;
}
}
}