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

Listening To MailMergeCommand

1 Answer 56 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
band
Top achievements
Rank 1
band asked on 16 Jan 2017, 04:57 PM

Hi,

Simple question, how can I subscribe to MailMergeCommand so that I can find out where the file is being saved. 

 

void radRichTextBox_CommandExecuted(object sender, CommandExecutedEventArgs e)
{
    if (e.Command is MailMergeCommand)
    {
       // File Dialog FilePath Location Code
    }
}
 
void radRichTextBox_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
    if (e.Command is MailMergeCommand)
    {
         
    }
}

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 19 Jan 2017, 12:08 PM
Hello Band,

The MailMergeCommand doesn't give access to the dialog path where the file will be saved. In order to achieve your requirement you can use the CommandExecuting event to cancel the MailMergeCommand and then implement custom logic that manually calls the mail merge feature. This way you can get the save path.
private void richTextBox_CommandExecuting(object sender, Telerik.Windows.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is MailMergeCommand)
    {                 
        SaveFileDialog saveDialog = new SaveFileDialog();
        saveDialog.Filter = "Word Documents (*.docx)|*.docx|Web Pages (*.html, *.htm)|*.html;*.htm|PDF Files (*.pdf)|*.pdf|Rich Text Format (*.rtf)|*.rtf|Text Files (*.txt)|*.txt|XAML Files (*.xaml)|*.xaml";
        bool? dialogResult = saveDialog.ShowDialog();
        if (dialogResult == true)
        {
            using (var outputStream = saveDialog.OpenFile())
            {
                var richTextBox = (RadRichTextBox)sender;
                var mergedDocument = richTextBox.MailMerge();
                DocxFormatProvider provider = new DocxFormatProvider();
                provider.Export(mergedDocument, outputStream);
            }
              var filePath = saveDialog.FileName;
        }
        e.Cancel = true;
    }
}

Regards,
Martin
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RichTextBox
Asked by
band
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or