K
Karl
Hi,
I have some code that will save the contents of a Rich Text Box in
either a Text or Rich Text Format file. The code is using the
SaveFileDialog and is working correctly.
I have been testing the code and added in some exception handling to
cater for any problems. During testing I have found that if I attempt
to save to a floppy disc that is full, a System.IO.IOException is raied
with the message "There is not enough space on the disk". I am catching
this exception to display a message to the user. I then Dispose of the
SaveFileDialog. I then perform Garbage Collection via GC.Collect and at
this point the exception is raised again but is not caught. Even if a
put a try around the GC.Collect and have a subsequent Catch the
exception is now handled.
Can someone explain what I'm doing wrong? I'm guessing that the
SaveFileDialog is retrying the save and I need to somehow flush it or
abort?
The code I'm using :
try
{
richTextBox.SaveFile (saveFileDialog1.FileName,
RichTextBoxStreamType.RichText);
}
catch (System.IO.IOException ex)
{
MessageBox.Show ("Error: " + ex.Message + "\n",
"Problem Saving the Results", MessageBoxButtons.OK);
}
saveFileDialog1.Dispose (); // Dispose of the save file dialog
try
{
GC.Collect (); // collect the garbage
}
catch (System.IO.IOException ex)
{
MessageBox.Show ("Error: " + ex.Message + "\n",
"Problem Saving the Results v2", MessageBoxButtons.OK);
}
catch ( Exception ex )
{
MessageBox.Show ("Error: " + ex.Message + "\n",
"Problem Saving the Results v3", MessageBoxButtons.OK);
}
I have some code that will save the contents of a Rich Text Box in
either a Text or Rich Text Format file. The code is using the
SaveFileDialog and is working correctly.
I have been testing the code and added in some exception handling to
cater for any problems. During testing I have found that if I attempt
to save to a floppy disc that is full, a System.IO.IOException is raied
with the message "There is not enough space on the disk". I am catching
this exception to display a message to the user. I then Dispose of the
SaveFileDialog. I then perform Garbage Collection via GC.Collect and at
this point the exception is raised again but is not caught. Even if a
put a try around the GC.Collect and have a subsequent Catch the
exception is now handled.
Can someone explain what I'm doing wrong? I'm guessing that the
SaveFileDialog is retrying the save and I need to somehow flush it or
abort?
The code I'm using :
try
{
richTextBox.SaveFile (saveFileDialog1.FileName,
RichTextBoxStreamType.RichText);
}
catch (System.IO.IOException ex)
{
MessageBox.Show ("Error: " + ex.Message + "\n",
"Problem Saving the Results", MessageBoxButtons.OK);
}
saveFileDialog1.Dispose (); // Dispose of the save file dialog
try
{
GC.Collect (); // collect the garbage
}
catch (System.IO.IOException ex)
{
MessageBox.Show ("Error: " + ex.Message + "\n",
"Problem Saving the Results v2", MessageBoxButtons.OK);
}
catch ( Exception ex )
{
MessageBox.Show ("Error: " + ex.Message + "\n",
"Problem Saving the Results v3", MessageBoxButtons.OK);
}