Esempio n. 1
0
        private void OpenDocument()
        {
            using (OpenFileDialog openDialog = new OpenFileDialog())
            {
                openDialog.Filter = "Word Documents (*.docx)|*.docx|Web Pages (*.htm,*.html)|*.htm;*.html|Rich Text Format (*.rtf)|*.rtf|Text Files (*.txt)|*.txt|XAML Files (*.xaml)|*.xaml";

                if (openDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string extension = Path.GetExtension(openDialog.SafeFileName).ToLower();

                    IDocumentFormatProvider provider = GetProviderByExtension(extension);

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

                    using (Stream stream = openDialog.OpenFile())
                    {
                        RadDocument document = provider.Import(stream);
                        this.DetachDocument(this.radRichTextBox1.Document);
                        this.radRichTextBox1.Document = document;
                        this.AttachDocument(document);
                        document.LayoutMode = DocumentLayoutMode.Paged;
                    }
                }

                this.radRichTextBox1.Focus();
            }
        }
Esempio n. 2
0
        private RadDocument LoadDocumentToInsert()
        {
            RadDocument document = null;

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Word Documents (*.docx)|*.docx|All Files (*.*)|*.*";

            if (ofd.ShowDialog() == true)
            {
                string extension;
#if SILVERLIGHT
                extension = ofd.File.Extension.ToLower();
#else
                extension = Path.GetExtension(ofd.SafeFileName).ToLower();
#endif

                IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

                Stream stream;
#if SILVERLIGHT
                stream = ofd.File.OpenRead();
#else
                stream = ofd.OpenFile();
#endif
                using (stream)
                {
                    document = provider.Import(stream);
                }
            }

            return(document);
        }
Esempio n. 3
0
 private void LoadDocument()
 {
     using (Stream stream = Application.GetResourceStream(GetResourceUri(SampleDocumentPath)).Stream)
     {
         IDocumentFormatProvider xamlProvider = DocumentFormatProvidersManager.GetProviderByExtension(".xaml");
         this.radRichTextBox.Document = xamlProvider.Import(stream);
     }
 }
Esempio n. 4
0
        private void OpenFile(object parameter)
        {
            RadOpenFileDialog ofd = new RadOpenFileDialog();

            string stringParameter = parameter as string;

            if (stringParameter != null && stringParameter.Contains("|"))
            {
                ofd.Filter = stringParameter;
            }
            else
            {
                string filter = string.Join("|", DocumentFormatProvidersManager.FormatProviders.Where(fp => fp.CanImport)
                                            .OrderBy(fp => fp.Name)
                                            .Select(fp => FileHelper.GetFilter(fp))
                                            .ToArray()) + "|All Files|*.*";
                ofd.Filter = filter;
            }

            if (ofd.ShowDialog() == true)
            {
                string extension;
                extension = Path.GetExtension(ofd.FileName).ToLower();

                IDocumentFormatProvider provider =
                    DocumentFormatProvidersManager.GetProviderByExtension(extension);

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

                try
                {
                    Stream stream;
                    stream = ofd.OpenFile();
                    using (stream)
                    {
                        RadDocument document = provider.Import(stream);
                        this.radRichTextBox.Document = document;
                        this.SetDocumentName(ofd.FileName);
                    }
                }
                catch (IOException)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileIsLocked"));
                }
                catch (Exception)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileCannotBeOpened"));
                }
            }
        }
Esempio n. 5
0
        private void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd    = new OpenFileDialog();
            string         filter = string.Join("|", DocumentFormatProvidersManager.FormatProviders
                                                .Where(fp => fp.CanImport)
                                                .OrderBy(fp => fp.Name)
                                                .Select(fp => this.GetFilter(fp))
                                                .ToArray()) + "|All Files|*.*";

            ofd.Filter = filter;

            if (ofd.ShowDialog() == true)
            {
                string extension = Path.GetExtension(ofd.SafeFileName).ToLower();

                this.provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

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

                try
                {
                    Stream stream;
                    stream = ofd.OpenFile();
                    using (stream)
                    {
                        RadDocument document = provider.Import(stream);
                        this.radRichTextBox.Document = document;

                        // Preserve the file name to use it when saving
                        this.path = ofd.FileName;
                    }
                }
                catch (IOException ex)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileIsLocked"));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileCannotBeOpened"));
                }
            }
        }
        private void ConvertFiles(object parameter)
        {
            ThreadParameters threadParameters = parameter as ThreadParameters;

            IDocumentFormatProvider fromFormatProvider =
                (threadParameters.FromFormatProvider == null) ? DocumentFormatProvidersManager.GetProviderByExtension(threadParameters.FileInfo.Extension) :
                threadParameters.FromFormatProvider;

            RadDocument document = null;

            using (Stream readStream = threadParameters.FileInfo.OpenRead())
            {
                document = fromFormatProvider.Import(readStream);
            }

            string fileName = Path.GetFileNameWithoutExtension(threadParameters.FileInfo.Name) + threadParameters.ToFormatProvider.SupportedExtensions.First();

            using (FileStream writeStream = new FileStream(this.toPath + "\\" + fileName, FileMode.Create))
            {
                document.EnsureDocumentMeasuredAndArranged();
                threadParameters.ToFormatProvider.Export(document, writeStream);
            }
        }
Esempio n. 7
0
        public void OpenFile(string parameter)
        {
            if (parameter != "")
            {
                string extension;
                extension = Path.GetExtension(parameter).ToLower();

                IDocumentFormatProvider provider =
                    DocumentFormatProvidersManager.GetProviderByExtension(extension);

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

                try
                {
                    Stream stream;
                    stream = File.Open(parameter, FileMode.Open);
                    using (stream)
                    {
                        RadDocument document = provider.Import(stream);
                        this.radRichTextBox.Document = document;
                        this.SetDocumentName(parameter);
                    }
                }
                catch (IOException)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileIsLocked"));
                }
                catch (Exception)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileCannotBeOpened"));
                }
            }
        }
Esempio n. 8
0
        private void OpenButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            string filter = string.Join("|", DocumentFormatProvidersManager.FormatProviders
                                                                           .Where(fp => fp.CanImport)
                                                                           .OrderBy(fp => fp.Name)
                                                                           .Select(fp => this.GetFilter(fp))
                                                                           .ToArray()) + "|All Files|*.*";
            ofd.Filter = filter;

            if (ofd.ShowDialog() == true)
            {
                string extension = Path.GetExtension(ofd.SafeFileName).ToLower();

                this.provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

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

                try
                {
                    Stream stream;
                    stream = ofd.OpenFile();
                    using (stream)
                    {
                        RadDocument document = provider.Import(stream);
                        this.radRichTextBox.Document = document;

                        // Preserve the file name to use it when saving
                        this.path = ofd.FileName;
                    }
                }
                catch (IOException ex)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileIsLocked"));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(LocalizationManager.GetString("Documents_OpenDocumentCommand_TheFileCannotBeOpened"));
                }
            }
        }