FileDialog.FileName Property


Gets or sets a string containing the file name selected in the file dialog box.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member FileName : string with get, set

Property Value

Type: System.String

The file name selected in the file dialog box. The default value is an empty string ("").

The file name includes both the file path and the extension. If no files are selected, this method returns an empty string ("").

When used from the SaveFileDialog class, this property represents the file being saved; when used from the OpenFileDialog class, it represents the file being opened.

This property can only be the name of one selected file. If you want to return an array containing the names of all selected files in a multiple-selection dialog box, use FileNames.

The following code example demonstrates using the RichTextBox.SaveFile and RichTextBox.LoadFile methods with streams. It also demonstrates using the FileName, DefaultExt, SaveFileDialog.CreatePrompt, and SaveFileDialog.OverwritePrompt members.

This is a complete example that is ready to run when you copy it to your project.

No code example is currently available or this language may not be supported.


to get or set the file name. Associated enumeration: PermissionState.Unrestricted.

.NET Framework
Available since 1.1
Return to top