Mail Merge Regions

Dear Sir / Madam,
I have an appointment letter formation in mail merge aspose. Based on some conditions which are string conditions few paragraphs will be seen otherwise not. For E.g If I belong to Senior Management Grade then I am going to be benefit with few Allowances which are mentioned in points. If I dont belong to Senior Management Grade I should not see that points at all. How can i check for String conditions in aspose.
Can any one help in solving my problem.
It is urgent…
Eagerly waiting for reply
Thanks & Regards
Geeta

Hi
Thanks for your request. I think that you can achieve this using MergeField event handler. For example see the following code:

public void Test()
{
    //Open template
    Document doc = new Document("in.doc");
    //Add MergeField event handler
    doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);
    //Execute mail merge
    doc.MailMerge.ExecuteWithRegions(table);
    //Save output document
    doc.Save("out.doc");
}
void MailMerge_MergeField(object sender, MergeFieldEventArgs e)
{
    if (e.FieldName == "myField")
    {
        //Here you can insert your condition logic
        //and do something with document
    }
}

Also see the following links for more information.
https://reference.aspose.com/words/net/aspose.words.mailmerging/ifieldmergingcallback/
Best regards.

Thanks for the help. But as i am new to aspose i am bit finding it diffiicult to handle the previous code. Can u send me some more links or sample code to use the Regions with aspose mail merge.
Even i request you to send me the code in vb.net as i am into asp.net development not C# i am not having much idea.
Waiting for the reply.
Thanks & Regards
Geeta

Hi
Thanks for your request. Here is code example how you can perform mail merge with regions and use MergeField event handler. Also see attached template.

Dim mCurrentName As String
Sub Main()
Dim lic As Aspose.Words.License = New Aspose.Words.License()
lic.SetLicense("Aspose.Words.lic")
Dim table As New DataTable("MyTable")
table.Columns.Add("Name")
table.Columns.Add("Option1")
table.Columns.Add("Option2")
table.Columns.Add("Option3")
table.Columns.Add("Option4")
table.Columns.Add("Option5")
Dim noRep As Integer = 0
For i As Integer = 0 To 4
noRep = i
table.Rows.Add(New Object() {"Alexey" & i.ToString(), "Option1", "Option2", "Option3", "Option4", "Option5"})
Next
'Open template document
Dim doc As New Document("in.doc")
'Add MergeField event handler
AddHandler doc.MailMerge.MergeField, AddressOf HandleMergeField
'Execute mail merge with regions
doc.MailMerge.ExecuteWithRegions(table)
'Save output document
doc.Save("out.doc")
End Sub
Sub HandleMergeField(ByVal sender As Object, ByVal e As Aspose.Words.Reporting.MergeFieldEventArgs)
'Here you can place your conditional logic
If (e.FieldName = "Name") Then
mCurrentName = e.FieldValue
Else
If (e.FieldName = "Option1" And mCurrentName = "Alexey0") Then
e.Field.Remove() 'dont show Option1 if name is Alexey0
End If
End If
End Sub

Also see the following links.
https://docs.aspose.com/words/net/types-of-mail-merge-operations/

Best regards.