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

Behind code Mail Merge Moving through Indexes

1 Answer 12 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Minh
Top achievements
Rank 1
Minh asked on 29 Mar 2016, 01:59 PM

Hi,I'm currently working with all MailMerge Documents. Is there a way to grab the Mail Merge document value without disrupting the UI thread. 

 

this.radRichTextBox.Document.MailMergeDataSource.MoveToIndex(index);

 

 

this.radRichTextBox.Document.MailMergeDataSource.MoveToIndex(counter);
this.radRichTextBox.Document.MailMergeDataSource.MoveToIndex(counter);

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 01 Apr 2016, 11:31 AM
Hi Minh,

You could use a background thread that executes the Merge operation. In order to pass the document to execute on the background, you will need to export it and pass the result string to the other thread, which then could import it to create a RadDocument instance and merge the desired record from the source collection. Keep in mind that the thread must be with ApartmentState.STA.

Here is a sample code that uses a separate thread to perform a Mail Merge and save the document to the file system:
XamlFormatProvider provider = new XamlFormatProvider();
string editorDocument = provider.Export(this.editor.Document);
 
Thread thread = new Thread(() =>
{
    RadDocument document = provider.Import(editorDocument);
    document.MailMergeDataSource.ItemsSource = new ExamplesDataContext().Employees;
                 
    // The MailMerge() method will merge all the records in the MailMergeDataSource. If you need to merge only a single record, you could use MailMergeCurrentRecord()
    RadDocument result = document.MailMerge();
 
    PdfFormatProvider pdfProvider = new PdfFormatProvider();
    using (FileStream stream = File.OpenWrite("result.pdf"))
    {
        pdfProvider.Export(result, stream);
    }
});
 
thread.SetApartmentState(ApartmentState.STA);
thread.Start();

Hope this helps.

Regards,
Tanya
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
Minh
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or