Probability of already existing file System.IO.Path.GetRandomFileName()
问题 Recently I got the 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 I used for generating file names: Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks + ".xlsx"); After realising that it is possible to create two files in one Tick, I changed the code to: Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + "