I've looked at other posts on here about this message, but none of them seem to match but scenario, hence the post.
I've trying to save a file (which works fine) but if the file is open but he user, then the exception is thrown (of course).
My question is : How do I save the file to a numerically prefixed name if the selected save as fix is already open?
Or
CATCH the exception to display a "don't be silly, close the file first, then save" message ?
The code I am (currently) using is
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
string filter = "CSV file (*.csv)|*.csv| All Files (*.*)|*.*";
saveFileDialog1.Filter = filter;
const string header = "CSV HEADER TITLES";
string LineOneData = Variables;
StreamWriter writer = null;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filter = saveFileDialog1.FileName;
using (writer = new StreamWriter(filter))
{
writer.WriteLine(header);
writer.WriteLine(LineOneData);
writer.Close();
}
}