public static string GetTempFileName(string extension)
{
FileStream f = null;
string path;
Random rnd;
int num = 0;
if (! String.IsNullOrEmpty (extension) && extension [0] != '.')
extension = "." + extension;
rnd = new Random ();
do {
num = rnd.Next ();
num++;
path = Path.Combine (Path.GetTempPath(), "tmp" + num.ToString("x") + extension);
try {
f = new FileStream (path, FileMode.CreateNew);
} catch { }
} while (f == null);
f.Close();
return path;
}