Behind code Mail Merge Moving through Indexes

2 posts, 0 answers
  1. Minh
    Minh avatar
    43 posts
    Member since:
    May 2014

    Posted 29 Mar 2016 Link to this post

    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. 





  2. Tanya
    Tanya avatar
    764 posts

    Posted 01 Apr 2016 Link to this post

    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);

    Hope this helps.

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top