private void CommandBinding_Executed_1(object sender, ExecutedRoutedEventArgs e) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "Rich Text Format (*.rtf)|*.rtf|All files (*.*)|*.*"; if (dlg.ShowDialog() == true) { FileStream fileStream = new FileStream(dlg.FileName, FileMode.Create); TextRange range = new TextRange(rbrEditor.Document.ContentStart, rbrEditor.Document.ContentEnd); range.Save(fileStream, DataFormats.Rtf); } }
public DocumentPaginator GetPaginator(double pageWidth, double pageHeight) { TextRange originalRange = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd); MemoryStream memoryStream = new MemoryStream(); originalRange.Save(memoryStream, DataFormats.Xaml); FlowDocument copy = new FlowDocument(); TextRange copyRange = new TextRange(copy.ContentStart, copy.ContentEnd); copyRange.Load(memoryStream, DataFormats.Xaml); return(new PrintingPaginator(((IDocumentPaginatorSource)copy).DocumentPaginator, new Size(pageWidth, pageHeight), new Size(DPI, DPI))); }
private void Save_Executed(object sender, ExecutedRoutedEventArgs e) { //To Microsoft.Win32 i System.Windows.Forms jest, aby można było dodać using Microsoft.Win32, żeby działał colordialog, bo inaczej visual się kłóci, bo w WPF nie ma colordialog i trzeba użyć opcji dostępnych w windows forms Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.Filter = "Rich Text Format (*.rtf)|*.rtf|Wszystkie pliki (*.*)|*.*"; if (dlg.ShowDialog() == true) { FileStream fileStream = new FileStream(dlg.FileName, FileMode.Create); TextRange range = new TextRange(editorRTB.Document.ContentStart, editorRTB.Document.ContentEnd); range.Save(fileStream, System.Windows.Forms.DataFormats.Rtf); } }
public bool SaveDocument() { if (string.IsNullOrEmpty(currentFile)) { return(SaveDocumentAs()); } using (Stream stream = new FileStream(currentFile, FileMode.Create)) { TextRange range = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd); range.Save(stream, DataFormats.Rtf); } return(true); }
private void SaveFile() { try { SaveFileDialog saveFileDialog = new SaveFileDialog { FileName = "My text.txt", InitialDirectory = @"D:\" }; saveFileDialog.Filter = "My text files (*.txt)|*.txt|My rich text files(*.rtf)|*.rtf|My XAML files (*.xaml)|*.xaml| All files (*.*)|*.*"; if (saveFileDialog.ShowDialog() == true) { TextRange textRange = new TextRange(this.MainText.Document.ContentStart, this.MainText.Document.ContentEnd); using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create)) { switch (System.IO.Path.GetExtension(saveFileDialog.FileName).ToLower()) { case ".rtf": textRange.Save(fs, DataFormats.Rtf); break; case ".txt": textRange.Save(fs, DataFormats.Text); break; default: textRange.Save(fs, DataFormats.Xaml); break; } } } } catch (Exception) { MessageBox.Show("Save error"); } }
//Open i Save: private void Save() { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.Filter = "Rich Text Format (*.rtf)|*.rtf|All files (*.*)|*.*"; if (dlg.ShowDialog() == true) { FileStream fileStream = new FileStream(dlg.FileName, FileMode.Create); TextRange range = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd); range.Save(fileStream, System.Windows.DataFormats.Rtf); saved = true; exists = true; filePath = dlg.FileName; } }
public void Save_Click(object sender, RoutedEventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*"; if (sfd.ShowDialog() == true) { TextRange doc = new TextRange(docBox.Document.ContentStart, docBox.Document.ContentEnd); using (FileStream fs = File.Create(sfd.FileName)) { //if (System.IO.Path.GetExtension(sfd.FileName).ToLower() == ".txt") //{ doc.Save(fs, DataFormats.Text); //} } } }