protected string GenRandomFileName (string basepath, string ext) { if (rnd == null) rnd = new Random (); FileStream f = null; string path = null; do { int num = rnd.Next (); num++; path = Path.Combine (basepath, num.ToString ("x")); if (ext != null) path = String.Format ("{0}.{1}", path, ext); try { f = new FileStream (path, FileMode.CreateNew); } catch (System.IO.IOException) { f = null; continue; } catch { throw; } } while (f == null); f.Close (); return path; }