I recently got an exception:
Message:
System.IO.IOException: The file 'C:\Windows\TEMP\635568456627146499.xlsx' already exists.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
This was the result of the following code that I used to create the file names:
Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks + ".xlsx");
Realizing that you can create two files in one tick, I changed the code to:
Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".xlsx");
But I'm still wondering what is the likelihood of this exception in the new case?
source
share