Lotusscript version of LocalBrowse


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
  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 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))
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

  Exit Function

  Messagebox "Unexpected error: " & Error$ & " (" & Cstr(Err) & ").", 0, "Error"
  Resume lblEnd
End Function

Further reading



  1. Hi Ben Great site. Tried to use you code but got following error: Illegal parenthasized reference: GETWINDOW Any ideas would be greatfully appreciated. Cheers JonathonJonathon Thomas#
  2. Sorry, stupid typo in my source (I tested it, must be HTML skills…

    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#
  3. I'll Echo Jonathon's comments. Terrific stuff! Works just great for me. Thanks.

    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#
  4. Ralph, "but don't share your passion quite enough to play around with myself." I think you meant to say: "but don't share your passion quite enough to play around with IT myself." :-) Cheers !Dan#
  5. I've been looking all over for a "getopenfilename" but where a folder is selected instead of an actual file.. And here you adapted it for Lotus Notes.. Thanks man, you've made my life a lot easier!! :)P#
  6. In R6.5, there's an undocumented typecode in lotusScript that does the same thing as @Prompt([LocalBrowse]). The value returned is the filepath.

    Dim ws as NotesUIWorkspace
    Set ws = New NotesUIWorkspace

    targetfile = ws.Prompt(12,"Choose file","Choose file")

  7. There's also the OpenFileDialog method of the NotesUIWorkspace.Chris Crompton#
  8. @ Chris…

    OpenFileDialog is for opening FILES. This code is all about getting a handle on a FOLDER.

    Cheers.Ben Poole#
  9. Just what I needed… Thanks!

    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#

Comments on this post are now closed.


I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

File Attachment Icon