FileName Property

See Also3X3KWK                 ExampleK7FMML>Low

Applies To

Common dialog1H1HYJI, file list box1M6S8UX.


Determines the path and file name of a selected file.  Not available at design time.


[form.] commondialog | filelistbox}.FileName[ = filename ]


The FileName property is set to a null string (""), meaning no currently selected file, when the control is created at run time.

In the common dialog control, you can set the FileName property before opening the dialog in order to set an initial file name.

Reading this property returns the currently selected file name from the list.  The path is retrieved separately, using the PathBKGP79 property.  The value is functionally equivalent to List(ListIndex).  If no file is selected, FileName returns a null string ("").

When setting this property:

         Including a drive, path, or pattern in the string changes the DriveYLV8AS, Path, and PatternXYKZRG properties accordingly.

         Including the name of an existing file (without wildcard characters) in the string selects the file.

         Changing the value of this property may also cause one or more of these events:  PathChange3811T7 (if you change the path); PatternChange2JU7UW9 (if you change the pattern); or DblClick2UG5QK1 (if you've assigned an existing file name).

         This property can be a qualified network path and filename using this syntax: \\servername\sharename\filename.


Data Type


See Also


Drive PropertyYLV8AS

List PropertyBKCX6E

ListIndex Property4K7KHR

Path PropertyBKGP79

PathChange Event3811T7

Pattern PropertyXYKZRG

PatternChange Event2JU7UW9


Programmer's Guide:

Chapter 18, "Using the File-System Controls"

Chapter 19, "Processing Files"

FileName Property Example

The example displays a message in a label when a file name in a file list box is double-clicked.  To try this example, paste the code into the Declarations section of a form that contains a label, a directory list box, and a file list box..  Then press F5 and double-click any file name in the file list box.

Sub Dir1_Change ()
  File1.Path = Dir1.Path     ' Set File1 path.
End Sub
Sub File1_PathChange ()
  Dir1.Path = File1.Path     ' Set Dir1 path.
End Sub
Sub File1_DblClick ()
  ' Display the selected file name when DblClicked.
  Label1.Caption = "Your selection: " + UCase(File1.FileName)
End Sub