public void LoadFile(object sender, EventArgs e) { var item = (Item)((TreeView)sender).SelectedItem;//This is gross, but TreeView doesnt' have a bindable SelectedItem if (item != null) { using (var fileStream = new FileStream(item.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (item.Path.Contains(".rtf")) { FlowDocument flowDocument = new FlowDocument(); TextRange textRange = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd); textRange.Load(fileStream, DataFormats.Rtf); Document = flowDocument; } else { var flowDocumentConverter = new DocxToFlowDocumentConverter(fileStream); flowDocumentConverter.Read(); Document = flowDocumentConverter.Document; } } } }
public virtual FlowDocument GetDocument(string path) { using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var flowDocumentConverter = new DocxToFlowDocumentConverter(stream); flowDocumentConverter.Read(); return(flowDocumentConverter.Document); } }
private void ReadDocx(string path) { if (!File.Exists(path)) { path = "scenario.docx"; } if (File.Exists(path)) { using (var stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { var flowDocumentConverter = new DocxToFlowDocumentConverter(stream); flowDocumentConverter.Read(); this.flowDocumentReader.Document = flowDocumentConverter.Document; this.Title = System.IO.Path.GetFileName(path); } } }