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