Tip

Open browser window to designated default drive/directory

Have you ever wanted to open the browser window to a drive/directory of your own choice? Have you found the workspace.OpenFileDialog method too restrictive (i.e., the window is too small to see the directory names)? This code lets you open the Microsoft browser window to a specified location. It restricts the user to selecting a folder/file below a specified root drive/directory. It works by initially returning the selected directory name, then getting its parent folder, and so on, up the directory path until it gets to the root drive. Note: Nearly all other examples found on Notes-related sites suggest the use of the 'SHBrowseForFolder' API call for this functionality. The problem, however, is that there is little (if any) documentation to indicate how to get it to default to a specified default drive.

Sub Click(Source As Button)
 
'-- This script uses the shell.application 
object's BrowseForFolder.
'-- Properties in shell.application are 
different from the FSO.
'-- If the folder has files in it, getting the 
folder path is easy.
'-- If not, the method is circuitous.
'-- there are various options demonstrated 
in this script. The other script,
'-- BrowseFunction.vbs, contains one funtion 
to just return the path of selected item.
 
 Dim ShellApp, FolderObject, ParentFolderObject
 Dim strDirectoryPath As String, 
strParentFolderName As String
 Const HOME_DRIVE = "C:"
 
 On Error Goto ErrorHandler
 
 strDirectoryPath = ""
 
 Set ShellApp = CreateObject("Shell.Application")
 
' The &H4000 part of the line of code below 
allows for the displaying of files !
' Set FolderObject = ShellApp.browseforfolder
(Clng(0), "Select a file:", &H4000, HOME_DRIVE )
 Set FolderObject = ShellApp.browseforfolder
(Clng(0), "Select a directory:", 0, HOME_DRIVE )
 
'--get title of chosen folder.
 strDirectoryPath = FolderObject.Title
 
'--show msgbox with path of folder selected,
 if found:
 If Instr( strDirectoryPath, ":" ) > 0 Then
  strDirectoryPath = HOME_DRIVE
 Else
  
  Do
   
   Set ParentFolderObject = 
FolderObject.ParentFolder
   strParentFolderName = 
ParentFolderObject.Title
   
   If Instr(strParentFolderName, ":") = 0 Then  
 '--it's a directory
    strDirectoryPath = strParentFolderName & "" 
& strDirectoryPath
   Else               '--it's a drive. 
extract root folder path (ex.: C: )
    strDirectoryPath = 
HOME_DRIVE & strDirectoryPath
    
    Exit Do
   End If
   
   Set FolderObject = ParentFolderObject
   
  Loop Until strParentFolderName = ""
  
 End If ' End of  - "If Instr( strDirectoryPath, ":" ) 
> 0 Then"
 
 Msgbox "Path of chosen folder:  
" & strDirectoryPath
 
 Set ParentFolderObject = Nothing
 Set FolderObject = Nothing
 Set ShellApp = Nothing
 
 Exit Sub
 
ErrorHandler:
 
 Exit Sub
 
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Declan Moore. Please let others know how useful it is via the rating scale at the end of the tip. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in April 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.