Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Path.GetRandomFileName Method

Definition

Namespace:
System.IO
Assemblies:
mscorlib.dll, System.Runtime.Extensions.dll
Assemblies:
netstandard.dll, System.Runtime.dll
Assembly:
System.Runtime.Extensions.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
Path.cs
Source:
Path.cs
Source:
Path.cs
Source:
Path.cs
Source:
Path.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Returns a random folder name or file name.

public:
 static System::String ^ GetRandomFileName();
public static string GetRandomFileName();
static member GetRandomFileName : unit -> string
Public Shared Function GetRandomFileName () As String

Returns

A random folder name or file name.

Examples

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 . . .

 */
Imports System.IO

Module Module1

 Sub Main()
 Dim result = Path.GetRandomFileName()
 Console.WriteLine("Random file name is " + result)
 End Sub

End Module

' This code produces output similar to the following:

' Random file name is w143kxnu.idj
' Press any key to continue . . .

Remarks

Unlike GetTempFileName, GetRandomFileName does not create a file.

Applies to


Feedback

Was this page helpful?