0 out of 1 rated this helpful - Rate this topic

Path.GetRandomFileName Method

Returns a random folder name or file name.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)
public static string GetRandomFileName()

Return Value

Type: System.String
A random folder name or file name.

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.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
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.
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>
What's the range of length of the random file name?
What's the range of length of the random file name?
What's the range of length of the random file name?
What's the range of length of the random file name?