Path.GetRandomFileName Method
.NET Framework 4
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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
More tips on older documentation
There are more tips on 3.5 version of this documentation. Change the version at top of page to go to these.
- 9/6/2010
- ooWaratah
Create a temp working directory
<code>
/// <summary>
/// Create a temp working directory
/// </summary>
/// <returns></returns>
private string GetTempDirectory()
{
string path = Path.GetRandomFileName();
Path.Combine(Path.GetTempPath(), path);
Directory.CreateDirectory(path);
return path;
}
</code>
/// <summary>
/// Create a temp working directory
/// </summary>
/// <returns></returns>
private string GetTempDirectory()
{
string path = Path.GetRandomFileName();
Path.Combine(Path.GetTempPath(), path);
Directory.CreateDirectory(path);
return path;
}
</code>
- 9/6/2010
- ooWaratah
What's the range of length of the random file name?
What's the range of length of the random file name?
- 6/25/2010
- Zhongjian Zhang
What's the range of length of the random file name?
What's the range of length of the random file name?
- 6/25/2010
- Zhongjian Zhang