public static string GetTempFileName ()
{
FileStream f = null;
string path;
Random rnd;
int num = 0;
rnd = new Random ();
do {
num = rnd.Next ();
num++;
path = Path.Combine (GetTempPath(), "tmp" + num.ToString("x") + ".tmp");
try {
f = new FileStream (path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.Read,
8192, false, (FileOptions) 1);
}
catch (SecurityException) {
// avoid an endless loop
throw;
}
catch (UnauthorizedAccessException) {
// This can happen if we don't have write permission to /tmp
throw;
}
catch (DirectoryNotFoundException) {
// This happens when TMPDIR does not exist
throw;
}
catch {
}
} while (f == null);
f.Close();
return path;
}