コード例 #1
0
        private void SaveDocument(string format)
        {
            using (SaveFileDialog saveDialog = new SaveFileDialog())
            {
                if (format == "docx")
                {
                    saveDialog.Filter = "Word Document (*.docx)|*.docx";
                }
                else if (format == "rtf")
                {
                    saveDialog.Filter = "Rich Text Format (*.rtf)|*.rtf";
                }
                else if (format == "html")
                {
                    saveDialog.Filter = "Web Page (*.html)|*.html";
                }
                else if (format == "xaml")
                {
                    saveDialog.Filter = "XAML File (*.xaml)|*.xaml";
                }
                else if (format == "txt")
                {
                    saveDialog.Filter = "Text File (*.txt)|*.txt";
                }
                else if (format == "pdf")
                {
                    saveDialog.Filter = "PDF File (*.pdf)|*.pdf";
                }
                else
                {
                    saveDialog.Filter = "Word Document (*.docx)|*.docx|PDF File (*.pdf)|*.pdf|Web Page (*.html)|*.html|Rich Text Format (*.rtf)|*.rtf|Text File (*.txt)|*.txt|XAML File (*.xaml)|*.xaml";
                }

                if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string extension = System.IO.Path.GetExtension(saveDialog.FileName);

                    IDocumentFormatProvider provider = GetProviderByExtension(extension);

                    if (provider == null)
                    {
                        RadMessageBox.Show("Unable to find format provider for extension " + extension, "Error");
                        return;
                    }

                    using (Stream output = saveDialog.OpenFile())
                    {
                        provider.Export(this.radRichTextBox1.Document, output);
                    }
                }

                this.radRichTextBox1.Focus();
            }
        }
コード例 #2
0
        private void AutoSave(object sender, EventArgs e)
        {
            IDocumentFormatProvider provider = GetProviderByExtension(".html");

            using (Stream output = new FileStream(path, FileMode.Create))
            {
                provider.Export(this.radRichTextBox1.Document, output);
            }
            ParentControl.Update();
            this.radRichTextBox1.Focus();
        }
コード例 #3
0
 private static void SaveFile(SaveFileDialog dialog, IDocumentFormatProvider provider, RadDocument document)
 {
     var result = dialog.ShowDialog();
     if (result == true)
     {
         try
         {
             using (var stream = dialog.OpenFile())
             {
                 provider.Export(document, stream);
             }
         }
         catch (IOException ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
コード例 #4
0
        private static void SaveFile(SaveFileDialog dialog, IDocumentFormatProvider provider, RadDocument document)
        {
            var result = dialog.ShowDialog();

            if (result == true)
            {
                try
                {
                    using (var stream = dialog.OpenFile())
                    {
                        provider.Export(document, stream);
                    }
                }
                catch (IOException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #5
0
        private void SaveDocument()
        {
            SaveFileDialog saveDialog      = new SaveFileDialog();
            var            formatProviders = DocumentFormatProvidersManager.FormatProviders.Where(fp => fp.CanExport);

            saveDialog.Filter = string.Join("|", formatProviders.Select(fp => GetFilter(fp)).ToArray()) + "|All Files|*.*";

            saveDialog.FilterIndex = 3;

            bool?dialogResult = saveDialog.ShowDialog();

            if (dialogResult == true)
            {
                string extension = Path.GetExtension(saveDialog.SafeFileName);
                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

                using (Stream output = saveDialog.OpenFile())
                {
                    provider.Export(this.radRichTextBox.Document, output);
                }
            }
        }
コード例 #6
0
        public string ExportContent(string defaultExtension,
                                    string filter,
                                    IDocumentFormatProvider formatProvider)
        {
            var saveFileDialog = new Microsoft.Win32.SaveFileDialog
            {
                DefaultExt = defaultExtension,
                Filter     = filter
            };

            var dialogResult = saveFileDialog.ShowDialog();

            if (dialogResult == true)
            {
                using (var outputStream = saveFileDialog.OpenFile())
                {
                    formatProvider.Export(radRichTextBox.Document, outputStream);
                }
            }

            return(saveFileDialog.FileName);
        }
コード例 #7
0
        private void SaveFile(object parameter)
        {
            string            extension    = null;
            Stream            outputStream = null;
            RadSaveFileDialog saveDialog   = new RadSaveFileDialog();
            string            exportFormat = parameter as string;

            if (exportFormat != null && exportFormat.Contains("|"))
            {
                saveDialog.Filter = exportFormat;
            }
            else
            {
                var formatProviders = DocumentFormatProvidersManager.FormatProviders;

                if (!string.IsNullOrEmpty(exportFormat))
                {
                    string[] extensions = exportFormat.Split(',', ';').Select(e => e.Trim('.').ToLower()).ToArray();
                    formatProviders = formatProviders.Where(fp => fp.SupportedExtensions.Any(ext => extensions.Contains(ext.Trim('.').ToLower())));
                }

                string filter = string.Join("|", formatProviders.Where(fp => fp.CanExport)
                                            .OrderBy(fp => fp.Name)
                                            .Select(fp => FileHelper.GetFilter(fp))
                                            .ToArray());
                saveDialog.Filter = filter;
            }

            bool?dialogResult = saveDialog.ShowDialog();

            if (dialogResult == true)
            {
                extension    = System.IO.Path.GetExtension(saveDialog.FileName);
                outputStream = saveDialog.OpenFile();

                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

                if (provider == null)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_SaveCommand_UnsupportedFileFormat"));
                    return;
                }

                if (provider is IConfigurablePdfFormatProvider)
                {
                    IConfigurablePdfFormatProvider pdfFormatProvider = (IConfigurablePdfFormatProvider)provider;
                    pdfFormatProvider.ExportSettings.CommentsExportMode =
                        this.radRichTextBox.ShowComments ? PdfCommentsExportMode.NativePdfAnnotations : PdfCommentsExportMode.None;
                }

                try
                {
                    using (outputStream)
                    {
                        provider.Export(this.radRichTextBox.Document, outputStream);
                        this.SetDocumentName(saveDialog.FileName);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_SaveCommand_UnableToSaveFile"));
                }
            }
        }