We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert Before Form Field Does Not Work

Hi All,

It seems that insert AFTER form field works and that is greate, however we need to insert a bullet before a formfield and that is not working.

bullet <>

bullet <>


We need the bullets to show only if the fields are there any insight?


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Every form field has bookmark that is associated with it. So you can move cursor of DocumentBuilder to start or to end of this bookmark and insert some text for example. If you need insert bullets before form fields then you can try using the following code.

//Open document

Document doc = new Document(@"Test134\in.doc");

//Create DocumentBuilder

DocumentBuilder builder = new DocumentBuilder(doc);

//Loop through all formfields in the focument

foreach (FormField field in doc.Range.FormFields)


//Move cursor to bookmarks that is associated with form field


//Aply bullet



//Save output document


I hope this could help you.

Also please provide me your document and code for reviewing.

Best regards.

We are creating a document in word and then running a merge using SQL and the document can be X.doc this time and Y.doc next time and Z.doc next time.

We have:

bullet field1

bullet field2

bullet field3

To recreate this create a document add some form fields edit the form fields and click the insert text before checkbox and add a bullet.

Run the doc and then have field3 be blank the bullet is still there and should not be.

Insert after works like it should if the field is blank don't insert the text.

Thanks for all your help

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please attach sample document here and provide me your code. I will investigate this issue and provide you more information.

Best regards.

Document doc = new Document(cstrForm);
MakeTable(dr); // From your Samples

for (int i = 0; i < myDataTable.Rows.Count; i++)
doc.MailMerge.MergeImageField += new MergeImageFieldEventHandler(HandleMergeImage);

DataRow dataRow = myDataTable.Rows[i];


Fields 40,42,44,46 have the insert before bullet.

Thanks for all your help

Also it seems that in word when a formfield is blank with an insert before the line below moves up, however Aspose.Words does not have this working/capability?




If field2 is blank field3 should move up?

Thanks again for all your help!

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for additional information.

1. There are no form fields in your document. These fields are called MergeFields.

2. You can add bullets during mail merge using MergeField event handler.

3. You can specify whether remove paragraphs that contained mail merge fields with no data using RemoveEmptyParagraphs property.

Please see the following code.

public void Test139()


//Open template document

Document doc = new Document(@"Test139\in.doc");

//Prepare data

string[] names = { "field40", "field42", "field44", "field46" };

string[] values = { "val1", "val2", "val3", "val4" };

//Add MergeField event handler

doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField139);

//Specifies whether paragraphs that contained mail merge fields with no data should be removed from the document.

doc.MailMerge.RemoveEmptyParagraphs = true;

//Execute mail merge

doc.MailMerge.Execute(names, values);

//Save document



void MailMerge_MergeField139(object sender, MergeFieldEventArgs e)


if (e.FieldName == "field40" || e.FieldName == "field42" || e.FieldName == "field44" || e.FieldName == "field46")


//Apply bullets




I hope this could help you.

Best regards.

Thank You for your speedy response.

You are correct MergeFields sorry about the terminology.

Is there no way to have the Mergefield be driven off the 'Insert Before?' from the document?

It seems like the 'Insert After' works fine.

Thanks again

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. It is not quite clear for me what you mean. During mail merge all merge fields are replaced with its values. Could you please attach your result document and document created by Word (that will show me what is wrong or what you would like to achieve).

Best regards.

if (e.FieldName == "field40" && e.FieldValue != null & e.FieldValue.ToString() != "")

Apply bullet

This does not seem to work? How would I apply to bullet to a field ONLY if it has a value?


Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for additional information. In my code I specify

doc.MailMerge.RemoveEmptyParagraphs = true;

So paragraphs that contained mail merge fields with no data will be removed from document. Have you tried using my code?

Could you please attach your output document for reviewing?

Best regards.