BrowseForFolder Method

Creates a dialog box that enables the user to select a folder and then returns the selected folder's Folder object.

Syntax

oFolder = Shell.BrowseForFolder(Hwnd, sTitle, iOptions [, vRootFolder])

Parameters

Hwnd Required. The handle to the parent window of the dialog box. This value can be zero.
sTitle Required. A String value that represents the title displayed inside the Browse dialog box.
iOptions Required. An Integer value that contains the options for the method. This can be zero or a combination of the values listed under the ulFlags member of the BROWSEINFO structure.
vRootFolder Optional. The root folder to use in the dialog box. The user cannot browse higher in the tree than this folder. If this value is not specified, the root folder used in the dialog box is the desktop. This value can be a string that specifies the path of the folder or one of the ShellSpecialFolderConstants values. Note that the constant names found in ShellSpecialFolderConstants are available in Microsoft Visual Basic, but not in Visual Basic Scripting Edition (VBScript) or Microsoft JScript. In those cases, the numeric values must be used in their place.

Return Value

An object reference to the selected folder's Folder object.

Examples

The following example uses BrowseForFolder to display a browse window titled "Example" rooted at the Windows folder. Proper usage is shown for JScript, VBScript, and Visual Basic.

JScript:

<script language="JScript">
    function fnShellBrowseForFolderJ()
    {
        var objShell = new ActiveXObject("Shell.Application");
        var ssfWINDOWS = 36;
        var objFolder;
        
        objFolder = objShell.BrowseForFolder(0, "Example", 0, ssfWINDOWS);
        if (objFolder != null)
        {
            // Add code here.
        }
    }
</script>

VBScript:

<script language="VBScript">
    function fnShellBrowseForFolderVB()
        dim objShell
        dim ssfWINDOWS
        dim objFolder
        
        ssfWINDOWS = 36
        set objShell = CreateObject("Shell.Application")
            set objFolder = objShell.BrowseForFolder(0, "Example", 0, ssfWINDOWS)
                if (not objFolder is nothing) then
                    'Add code here.
                end if
            set objFolder = nothing
        set objShell = nothing
    end function
 </script>

Visual Basic:

Private Sub fnShellBrowseForFolderVB()
    Dim objShell   As Shell
    Dim ssfWINDOWS As Long
    Dim objFolder  As Folder
    
    ssfWINDOWS = 36
    Set objShell = New Shell
        Set objFolder = objShell.BrowseForFolder(0, "Example", 0, ssfWINDOWS)
            If (Not objFolder Is Nothing) Then
                'Add code here
            End If
        Set objFolder = Nothing
    Set objShell = Nothing
End Sub

Applies To

Shell
Tags :


Community Content

Thomas Lee
Help!!!
In my page show "Access denied"... why ???

[tfl - 29/6/09] - You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn. You are much more likely get a quick response using the forums than through the Community Content.

My guess is that the folder you are trying to get to is not available to you - just tested it (using PowerShell) and it works fine!
Tags : forumpost

Thomas Lee
BrowseForFolder Sample Using PowerShell
# Browse-Folder.ps1
# MSDN Sample using PowerShell
# Thomas Lee - tfl@psp.co.uk

# First get shell object
$Shell = new-object -com Shell.Application

# Now Open up a browse window
$ssfWINDOWS = 36
$objFolder=$Shell.BrowseForFolder(0, "PowerShell Sample", 0, $ssfWINDOWS)

# display the selected folder
$objFolder

# Count the number of items in the selected folder
"This folder contains {0} items" -f ($objfolder.items()).count

This sample produces the following output on my ssytem, when the C:\Windows folder is selected:
PSH [D:\foo]: .\browse-folders.ps1

Title : WINDOWS
Application : System.__ComObject
Parent :
ParentFolder : System.__ComObject
Self : System.__ComObject
OfflineStatus : -1
HaveToShowWebViewBarricade : True
ShowWebViewBarricade : True

This folder contains 193 items


Page view tracker