I was recently trying to dump some Xml in a temp file to open it in Meta Edit and I found Path.GetTempFilename
Great I thought I can be lazy and use this to create a random filename and a path that would definetly be there on all machines, so I did the following:
string tempFilename = Path.GetTempFileName;
FileStream fs = new FileStream(tempFilename, FileMode.Create, etc .............
I got a file IO Exception, file already exists. Strange that the .Net method would not check that first so I did the following:
string tempFilename = Path.GetTempFileName;
while(File.Exists(tempFilename))
{
tempFilename = Path.GetTempFileName;
}
Whilst scratching my head wondering why my program had hung for the past 2 minutes i checked my temp folder, explorer crashed. Then my program hit a IO Exception, HD out of space. Then VS crashed.
143,000 files later I realised GetTempFilename doesn't just get you a file name, it creates the file.