Lotusscript version of LocalBrowse 01 Nov, 2002
Introduction
There's an undocumented @Prompt which allows the user to browse for a local folder: @Prompt([LocalBrowse]). I can't remember if this is implemented in NotesUIWorkspace.Prompt. So here's my Lotusscript version of this code. It's a function which returns a string. This string will be the full path to the folder, and you can then use this in your code as appropriate. The only thing you might want to change is the prompt, held in the property mBrowseInfo.lpszTitle.
The code uses Win32 function calls, so obviously it's only for that platform. I've tested this in Notes 5.05 on a machine running Windows 2000 Professional, so YMMV. The attachment comprises this exact same code in the form of a script library — you should be able to do a File / Import directly into the programming pane of a new script library, selecting this file along the way. I also show you an example call below.
Here are the bits of code which should go in your (Declarations) section. The first block defines the structure of BrowseInfo whilst the remaining blocks are function declarations used in the code. Note the use of GetActiveWindow. This is a particularly common function for anyone doing Win32 code in Lotusscript, as you need a handle on the window invoking your code in practically all such programming. The other functions provide interfaces to the actual folder browser mechanism in Windows, and also a function to help with grabbing the folder ID. You can find out more about these functions at the following URLs:
' Gets handle on current window
Declare Function GetActiveWindow Lib "user32.dll" () As Long
' BrowseInfo stucture
Type BROWSEINFO
hwndOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
' BrowseFlags constants
Const BIF_BROWSEFORCOMPUTER = 1000
Const BIF_BROWSEFORPRINTER = 2000
Const BIF_DONTGOBELOWDOMAIN = 2
Const BIF_RETURNFSANCESTORS = 8
Const BIF_RETURNONLYFSDIRS = 1
Const BIF_STATUSTEXT = 4
Const MAX_SIZE = 255
' Function to browse for folder (not files)
Declare Function BrowseFolderDlg Lib "shell32.dll" Alias "SHBrowseForFolder" (lpBrowseInfo As BROWSEINFO) As Long
' Function that returns path of selected folder
Declare Function GetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDList"_
(Byval PointerToIDList As Long, Byval pszPath As String) As Long
Here’s an example call:
Dim sPath As String
sPath = BrowseForFolder()
Messagebox "The folder you chose is '" & sPath
And here’s the code itself…
Function BrowseForFolder() As String
Dim mBrowseInfo As BROWSEINFO
Dim lngPointerToIDList As Long
Dim lngResult As Long
Dim strPathBuffer As String
Dim strReturnPath As String
Dim vbNullChar As String
vbNullChar = Chr(0)
On Error Goto lblErrs
mBrowseInfo.hwndOwner = GetActiveWindow()
' Set default folder for dialog box (0 = My Computer, 5 = My Documents)
mBrowseInfo.pidlRoot = 0
mBrowseInfo.lpszTitle = "Select the folder you wish to use:"
mBrowseInfo.pszDisplayName = String(MAX_SIZE, Chr(0))
mBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS
lngPointerToIDList = BrowseFolderDlg(mBrowseInfo)
If lngPointerToIDList <> 0& Then
strPathBuffer = String(MAX_SIZE, Chr(0))
' Get selected path
lngResult = GetPathFromIDList(Byval lngPointerToIDList, Byval strPathBuffer)
strReturnPath = Left$(strPathBuffer, Instr(strPathBuffer, vbNullChar) - 1)
End If
BrowseForFolder = strReturnPath
lblEnd:
Exit Function
lblErrs:
Messagebox "Unexpected error: " & Error$ & " (" & Cstr(Err) & ").", 0, "Error"
Resume lblEnd
End Function
try the code as it is now… you should be using "GetActiveWindow" (as in the Win32 function), not "GetWindow", which was a separate routine using GetActiveWindow in my original source code…
Silly meBen Poole#
Great site too. More stuff than I'll ever need. Your site is full of the kind of stuff that I dearly wish I knew a lot more about (API calls, Win API stuff etc etc) but don't share your passion quite enough to play around with myself. Keep up the good work.Ralph#
Dim ws as NotesUIWorkspace
Set ws = New NotesUIWorkspace
targetfile = ws.Prompt(12,"Choose file","Choose file")
Fred#
OpenFileDialog is for opening FILES. This code is all about getting a handle on a FOLDER.
Cheers.Ben Poole#
Additional options for the function:
- the title of the Dialog box
- the starting point in the tree, e.g. a point the user used the last time
SjefSjef Bosman#