Free Support Forum - aspose.com

Hi e.field.start is not working for me

hi,
could you plese help why my code is not working and it is giving error OBJECT REFERENCE IS NOT SET TO AN INSTANCE OF THE OBJECT . error while binging the merge fild with empty of dataset row

Aspose.Words.Node parentRow = e.Field.Start.GetAncestor(typeof(Row));
parentRow.Remove();


this is my mergefieldevent args is

void mailmergeEvent(object sender, MergeFieldEventArgs e)
{
if (string.IsNullOrEmpty(e.FieldValue.ToString()) || e.FieldValue== DBNull.Value )
{

Aspose.Words.Node parentRow = e.Field.Start.GetAncestor(typeof(Row));
parentRow.Remove();
}
}

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

Thanks for your inquiry. This occurs because current field is not placed in table. So GetAncestor(NodeType.Row) returns null. You should use the following code:

void MailMerge_MergeField264(object sender, MergeFieldEventArgs e)

{

if (string.IsNullOrEmpty(e.FieldValue.ToString()))

{

Aspose.Words.Node parentRow = e.Field.Start.GetAncestor(NodeType.Row);

if (parentRow!=null)

parentRow.Remove();

}

}

Hope this helps.

Best regards.

hi Alexey,

you have given to my problem and one thing is remained from WordDownlods… that is when i insert pagebreak one blank page is comming how to remove. i have attached my template. in that i am getting blank page after DownloadResult heading. can you plese go through it and give me solution…

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

Have you tried to use the template I attached in the following thread?

http://www.aspose.com/community/forums/2/133168/creating-and-inserting-rows-and-columns-using-builder/showthread.aspx#133168

I think this should solve your problem.

Best regards.