private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            var fileContent = string.Empty;
            RadOpenFileDialog openFileDialog = new RadOpenFileDialog()
            {
                Filter      = "|PDF Files (*.pdf)|*.pdf",
                FilterIndex = 1,
            };

            openFileDialog.ShowDialog();

            if (openFileDialog.DialogResult == true)
            {
                try
                {
                    Stream fileStream = openFileDialog.OpenFile();
                    ConvertPDF(fileStream);
                    MemoryStream ms = new MemoryStream(PDFBodyBytes);
                    EmptyContent.Visibility = Visibility.Collapsed;
                    PDFBody = new PdfDocumentSource(ms);
                    pdfViewer.DocumentSource = new PdfDocumentSource(ms);
                }
                catch
                {
                }
            }
        }
Exemplo n.º 2
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"));
                }
            }
        }
Exemplo n.º 3
0
        private void OnOpenFile(object sender, ExecutedRoutedEventArgs e)
        {
            var dialog = new RadOpenFileDialog()
            {
                Multiselect = false, Filter = "所有文件 (*.*)|*.*"
            };

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile()) {
                    Editor.Document.LoadFile(stream, Encoding.UTF8);
                }

                FilePath = dialog.FileName;
            }
        }