Path.GetRandomFileName Method
Returns a random folder name or file name.
Assembly: mscorlib (in mscorlib.dll)
The GetRandomFileName method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, GetRandomFileName does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.
The following example show output from the GetRandomFileName method.
using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string result = Path.GetRandomFileName(); Console.WriteLine("Random file name is " + result); } } } /* This code produces output similar to the following: Random file name is w143kxnu.idj Press any key to continue . . . */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.