Free Support Forum - aspose.com

Apply Custom Logic to Unmerged Regions using C#

Hello, at the moment we use an old version from 2008/2009 and want to upgrade to new version because we need to imiplement nested regions. At the moment i evaluate if all our requirements are covered with new release...

Now my current problem: I want to cover the sample "How-to: Apply Custom Logic to Unmerged Regions". I need 3 nested regions but in my sample project the databinding between the three DataTable-Queries i pass via

doc.MailMerge.ExecuteWithRegions(GetMietEigData());
doc.MailMerge.ExecuteWithRegions(GetTOPData());
doc.MailMerge.ExecuteWithRegions(GetAntragData());

has the result, that all records of GetAntragData are dispalyed in first merge region of GetTOPData and the Data of GetTopData is only replaced on first merge region of MietEigData…
how should i tell the 3 DataTable sources, on which fields they are related on each other?

Best regards


This message was posted using Banckle Live Chat 2 Forum

Hi Alwin,

Thanks for your query. Please find the sample code in attachment to apply custom logic to empty regions. Hope this answers your query. For your kind reference, please read following mail merge articles.
How to Set up Relations for use in Nested Mail Merge with Regions
How to Execute Mail Merge with Regions

Hi there,


Thanks for your inquiry.

Just to clarify, the original article you are talking about is for working with empty regions that are left over after mail merge in executed. Since you are trying to execute mail merge and not get rid of empty regions you should be using the built-in mail merge features on there own.

The links that Tahir has provided is the code that you need to follow. You need to load your DataTable objects into a DataSet and setup relations in the DataSet. After that is done, nested mail merge should work as expected.

Thanks,

That's exactly what i needed to know! It works fine now. Thanks!

At this point i got another question:
How can i insert a page break starting on odd pages using TableStart/End functionality?
I need to start each record on odd pages so a merged document can be printed duplex, starting each record on a new paper while printing...

Best regards

Hi there,

Thanks for this additional information.

Sure you can do this. I’m afraid you cannot insert a section break directly inside a region as a region must be formed inside the same section.

You can still achieve this using a bit of code. You will simply need to insert a bookmark called “SectionBreakPlaceHolder” inside at the very end of the region e.g just before the last TableEnd merge field. You can learn how to insert bookmarks into your template here:
Working with Bookmarks

Then you need to run this code after executing mail merge:

Node[] bookmarks = doc.GetChildNodes(NodeType.BookmarkStart,
true).ToArray();
foreach (BookmarkStart start in bookmarks)
{
    if (start.Name == "SectionBreakPlaceHolder")
    {
      builder.MoveTo(start);
      builder.InsertBreak(BreakType.SectionBreakOddPage);
      start.Bookmark.Remove();
   }
}

If we can help with anything else, please feel free to ask.

Thanks,