API
@-Formulas
JavaScript
LotusScript
Reg Exp
Web Design
Notes Client
XPages
 
Get Single File Name
Although the syntax for the NotesUIWorkspace.OpenFileDialog is pretty easy to work with, we had this reusable script library that provides an easy interface to get a file name from the user. You pass in a window title and a filter string, and you'll get back the full path to the selected file, or an empty string if the user clicked Cancel.

For the filter, the format is exactly what the NotesUIWorkspace.OpenFileDialog requires for a format. For each type of file you can select, you include two values with a vertical bar character between. For example, if you want to give the user the ability to select Notes databases, then your filter should be "Notes Databases|*.nsf". The first part is what is shown in the dialog box (the "common name" the user picks) and the second is the actual file extension filter. If you want to include multiple types of files, then each group of two is separated with a vertical bar, as in "Notes Databases|*.nsf|Notes Templates|*.ntf".

Note that the dialog box starts out in the user's Notes data directory, but they can choose any directory. The return value is the full path to the selected file.

Function GetSingleFileName(windowTitle As String, filters As String) As String
   Dim session As New NotesSession
   Dim ws As New NotesUIWorkspace
   Dim dataDir As String
   Dim files As Variant
   
   dataDir = session.GetEnvironmentString("Directory", True)
   files = ws.OpenFileDialog(False, windowTitle, filters, dataDir)
   
   If Isempty(files) Then
      GetSingleFileName = ""
   Elseif Not Isarray(files) Then
      GetSingleFileName = Cstr(files)
   Else
      GetSingleFileName = files(Lbound(files))
   End If
End Function