I don't think it will make any real difference, but I would streamline that a little:
string folder = @"C:\LABREPORTS\" + patnumber;
string file = string.Format(@"{0}\{1}.txt", folder, orderno):
if (!Directory.Exists(folder))
{
Directory.CreateDirectory(folder);
}
File.Delete(file);
using (StreamWriter writer = new StreamWriter(file, false))
{
writer.Write(report.ToString());
}
The File.Delete documentation says it doesn't throw an exception if the file doesn't exist, so why check? You shouldn't need to delete it either, but to be sure...:laugh:
The StreamWriter has an overload that takes the path and a "Append" option, so that is a little clearer.
If you are just writing the one set of info to the file, I would use
File.Delete(file);
File.WriteAllText(report.ToString());
But I can't see anything absolutely wrong with your code - are you sure it is being appended? I would append the data and the folder/file names to a log file to be sure I was writing the correct file as well, (or use the debugger to check the file immediately before the stream writer creation and again after the dispose.)