First backup your original file. write your file in a temp location, and
then copy it over to the new location. Now what happens at copy over,
restore from backup. So the file is place safe, if your back failed, that
might a situation. So the other option is to store incremental parts of
information in separate files, so not the entire program's data is lost, and
some recovery is available. Again if you access to many files it might be
slow to program, so essentially its balance of what's important to you.
The software can only to a extent provide fail safe mechanism, using
computers you need to learn to backup, else you are in trouble.
Did I answer your question or ramble too much??
VJ
"Gary Brown" <ga********@charter.netwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
Hi,
If there is an exception during writing a file with StreamWriter how
do you abort the creation of the new file? Due to introducing a bug
an existing file was lost (backed-up, fortunately) when the "Write"
hit the bug. The incomplete file closed and overwrote its
predecessor. How do I prevent this from happening again? The
catches didn't.
The abbreviate code is:
using (StreamWriter SW = new StreamWriter(Filepath))
{
try
{
Write(SW);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "...");
throw;
}
}
catch (Exception e) { MessageBox.Show(e.Message, "..."); }
Thanks,
Gary