private void Open(string fileName)
        {
            string extension = Path.GetExtension(fileName);
            IFormatProvider <RadFlowDocument> provider = this.providers
                                                         .FirstOrDefault(p => p.SupportedExtensions
                                                                         .Any(e => string.Compare(extension, e, StringComparison.InvariantCultureIgnoreCase) == 0));

            if (provider != null)
            {
                using (Stream stream = File.OpenRead(fileName))
                {
                    try
                    {
                        this.document = provider.Import(stream);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Could not open file.");
                        this.document = null;
                    }
                }
            }
            else
            {
                Console.WriteLine("Could not open file.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads the file from the disk as an in-memory document, based on the provided path
        /// </summary>
        /// <param name="path">Path to the file on disk you wish to import</param>
        /// <returns>RadFlowDocument that you can use to convert the contents to other formats</returns>
        RadFlowDocument ReadFile(string path)
        {
            IFormatProvider <RadFlowDocument> fileFormatProvider = GetImportFormatProvider(Path.GetExtension(path));

            RadFlowDocument document;

            using (FileStream input = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                document = fileFormatProvider.Import(input);
            }

            return(document);
        }
Exemplo n.º 3
0
        private void Open(object obj)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter      = "Docx files|*.docx|Rtf files|*.rtf|Html files|*.html|Text files|*.txt|All files (*.*)|*.*";
            dialog.FilterIndex = 1;
            if (dialog.ShowDialog() == true)
            {
                string extension = Path.GetExtension(dialog.FileName);
                IFormatProvider <RadFlowDocument> provider = this.providers
                                                             .FirstOrDefault(p => p.SupportedExtensions
                                                                             .Any(e => string.Compare(extension, e, StringComparison.InvariantCultureIgnoreCase) == 0));

                if (provider != null)
                {
                    using (Stream stream = dialog.OpenFile())
                    {
                        try
                        {
                            this.Document = provider.Import(stream);
                            this.FileName = Path.GetFileName(dialog.FileName);
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Could not open file.");
                            this.Document = null;
                            this.FileName = null;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Could not open file.");
                }
            }
        }