C#

C#

Made by DeepSource

Use Path.GetTempFileName() to generate unique filenames rather than relying on DateTime CS-S1004

Security
Major

One way to generate unique files is to rely on DateTime.Now.Ticks and then append this filename to the temp path. However, .NET provides APIs to generate reliable temp files. You can combine Path.GetTempPath() and Path.GetTempFileName() to get the full path to a uniquely generated file that is comparatively more secure and reliable.

Bad Practice

var temp = Path.Combine(Path.GetTempPath(), DateTime.Now.Ticks + ".tmp");

Recommended

var temp = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());