This is a migrated thread and some comments may be shown as answers.

MailMerge produces identical documents with identical addressee

2 Answers 52 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Joachim
Top achievements
Rank 1
Joachim asked on 19 Jul 2016, 01:01 PM

Dear support,

we are facing rather often but nevertheless unpredictably the problem that the mail merge functionality produces identical documents. This is the part of code

01.public static IList<object> GetMailMergeBinaryResultDocuments
02.                     (byte[] source, IEnumerable mailMergeDataSource)
03.{
04.  if (mailMergeDataSource == null)
05.  {
06.    throw new ArgumentNullException("mailMergeDataSource");
07.  }
08. 
09.  RadDocument masterDocument = XamlFormatProvider.Import(source);
10.  masterDocument.MailMergeDataSource.ItemsSource = mailMergeDataSource;
11.  RadDocumentEditor radDocumentEditor = new RadDocumentEditor(masterDocument);
12. 
13.  radDocumentEditor.ChangeAllFieldsDisplayMode(FieldDisplayMode.Result);
14. 
15.  List<object> resultDocuments = new List<object>();
16.  masterDocument.MailMergeDataSource.MoveToFirst();
17. 
18.  do
19.  {
20.    resultDocuments.Add(masterDocument.MailMergeCurrentRecord());
21.  }
22.  while (masterDocument.MailMergeDataSource.MoveToNext());
23. 
24.  return resultDocuments;
25.}

 

where we know that different mail merge information was passed but for some reason was not processed correctly.

Can you help?

 

Regards   Jo

2 Answers, 1 is accepted

Sort by
0
Boby
Telerik team
answered on 21 Jul 2016, 07:27 AM
Hi Joachim,

I was not able to reproduce such issue with the provided code; so maybe the problem lies outside it. Could you open a support ticket and send us sample runnable project that reproduces it? This will help us investigate the issue further. 

As a side note - on possible problem that may affect you with this method is that 
MailMergeDataSource.MoveToFirst won't work if the IEnumerable source is not materialized. In this case, invoking ToList on the source will ensure that the the source is prepared for mail merge:
var enumerable = GetPersons();
 
var documents = GetMailMergeBinaryResultDocuments(File.ReadAllBytes(@"c:\temp\xaml.xaml"), enumerable.ToList());
where
private IEnumerable<Person> GetPersons()
{
    yield return new Person() { FirstName = "John", LastName = "Smith" };
    yield return new Person() { FirstName = "Robert", LastName = "Brown" };
    yield return new Person() { FirstName = "James", LastName = "Miller" };
}

I am mentioning this as it may be also related to your problem.


Regards,
Boby
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Joachim
Top achievements
Rank 1
answered on 03 Aug 2016, 10:03 AM

Hi Boby,

unfortunately your suggest did not change anything. I´ll try to build a small application which reproduces the problem. That´ll take some time. Thanks so far.

Regards  Jo

Tags
RichTextBox
Asked by
Joachim
Top achievements
Rank 1
Answers by
Boby
Telerik team
Joachim
Top achievements
Rank 1
Share this question
or