-
December 12th, 2009, 11:04 PM
#1
Saving a RTB in WPF using SaveFileDialog
I have a rich text box, and am having difficulty saving my file using the save file dialog (I want to let the user be able to browse to a specific location on their computer.) Could anyone please help me.
-
December 13th, 2009, 02:30 PM
#2
Re: Saving a RTB in WPF using SaveFileDialog
What exactly are you having trouble with? Can't get the file save dlg to display? Can't write out the data to the file?
-
December 13th, 2009, 03:39 PM
#3
Re: Saving a RTB in WPF using SaveFileDialog
Problem Solved now. But I am having one other little issue. When I have a rich text box that is blank, I want a messagbox to display saying that it is not possible to save a blank textbox. I have tried if/else statements but this did not seem to work. Here is the code below.
private void button4_Click(object sender, RoutedEventArgs e)
{
TextRange textRange = new TextRange(richTextBox2.Document.ContentStart, richTextBox2.Document.ContentEnd);
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "pdb Files (*pdb) | * pdb";
if (dlg.ShowDialog() == true)
{
using (FileStream fs = new FileStream(dlg.FileName, FileMode.OpenOrCreate))
{
textRange.Save(fs, DataFormats.Text);
-
December 13th, 2009, 03:53 PM
#4
Re: Saving a RTB in WPF using SaveFileDialog
I would approach that problem differently.
Instead of being reactive and telling the user that they can't save an empty document after they've tried to save, I would be proactive and only enable the save button if there is something to save.
To do this, handle the TextChanged event and check the size of the content. If it's zero, then disable the save button; otherwise enable it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|