Shell.BrowseForFolder method
Applies to: desktop apps only
Creates a dialog box that enables the user to select a folder and then returns the selected folder's Folder object.
Syntax
retVal = Shell.BrowseForFolder( Hwnd, sTitle, iOptions, [ vRootFolder ] )
Parameters
- Hwnd [in]
-
Type: Integer
The handle to the parent window of the dialog box. This value can be zero.
- sTitle [in]
-
Type: BSTR
A String value that represents the title displayed inside the Browse dialog box.
- iOptions [in]
-
Type: Integer
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 [in, optional]
-
Type: Variant
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 Visual Basic, but not in VBScript or JScript. In those cases, the numeric values must be used in their place.
Return value
Type: FOLDER**
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
Requirements
|
Minimum supported client | Windows 2000 Professional, Windows XP |
|---|---|
|
Minimum supported server | Windows 2000 Server |
|
Header |
|
|
IDL |
|
|
DLL |
|
Send comments about this topic to Microsoft
Build date: 3/7/2012
- 12/21/2011
- mystifeid
- 4/2/2012
- Thomas Lee
'############################# ShowOpenFolder #################################
'This function creates OpenFolder Dialog box in VbScript
'Designed by Rajendra Khope
Function ShowOpenFolder()
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Dim objShell
Dim objFolder
Dim objFolderItem
Dim strPath
Dim objPath
'Refer this Link http://msdn.microsoft.com/en-us/library/bb774085(VS.85).aspx
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path
'This for all - http://msdn.microsoft.com/en-us/library/ff521729(v=VS.85).aspx
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select folder to Save File:", OPTIONS, strPath)
If objFolder Is Nothing Then
ShowOpenFolder="C:"
Exit Function
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
ShowOpenFolder = objPath
End Function
'######################################################################
- 6/12/2010
- Rajendra_Khope
# 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
- 6/29/2008
- Thomas Lee
- 6/30/2008
- Thomas Lee
[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!
- 6/27/2008
- wanselmo
- 6/29/2008
- Thomas Lee