System.Shell.chooseFile Method

Displays a file picker dialog box and retrieves a System.Shell.Item object that represents the selected file.

Syntax

oShellItem = System.Shell.chooseFile(
  bForOpen,
  strFilter,
  strInitialDirectory,
  strFileInit
)

Parameters

  • bForOpen [in]
    BOOL Sets Boolean that specifies the type of file picker dialog box to display.
    Value Meaning
    true

    Open.

    false

    Save As.

     
  • strFilter [in]
    BSTR Sets String that specifies file descriptions and extensions. This string is in the format "Description:*.Extension:Description:*.Extension::".
  • strInitialDirectory [in]
    BSTR Sets String that specifies the root directory. Note  If an empty string is specified, the root directory is set to the users desktop (%USERPROFILE%\Desktop).
  • strFileInit [in]
    BSTR Sets String that specifies the file name.
  • oShellItem [out]
    object Sets A System.Shell.Item that represents the selected file.

Return Value

HRESULT

If the method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

strFilter requires the double-colon terminator as the filter string must be terminated by two NULL characters.

The first string in each pair is a display string that describes the filter (for example, Text Files), and the second string specifies the filter pattern (for example, *.TXT). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, *.TXT;*.DOC;*.BAK). A pattern string can be a combination of valid file name characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string.

The system displays the filters in the order specified by strFilter in the File Types combo box.

If strFilter is an empty string, the dialog box does not display any filters.

The chooseFile Open dialog box:

 

File picker 'Open' dialog box.

 

The chooseFile Save As dialog box:

 

File picker 'Save As' dialog box.

 

Examples

The following example demonstrates how to specify .txt and .reg files for the file picker dialog box.

// Create a shell item object.
var oShellItem = System.Shell.chooseFile(true, "Text File:*.txt:Reg File:*.reg::", "C:\\", "");

Requirements

Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
IDL Sidebar.idl
DLL Sidebar.Exe version 1.00 or later

See Also

System.Shell

 

 

Send comments about this topic to Microsoft

Build date: 2/24/2010

Build type: SDK