R4.6. He needed a routine to display a File-Open dialogbox, select a file and
attach it to the open document. We were able to get most of the way using
@Prompt([LOCALBROWSE]) which is undocumented in R4.6, but still works. However,
it always started in the NOTES\DATA directory, and there wasn't any way to pass
it a different initial directory to display.
The following accomplishes that function and more... The wName string variable
passes the initial directory into the function and holds the selected filename
after the user clicks OK.
The wTypeList string passes file-type filters into the function that the user
can select from a drop-down list. You can have multiple filters, separated by a
vertical bar, but each filter must have two elements, also separated by a
vertical bar (1) the label to be displayed in the drop-down list and (2) the
file-system filter (i.e. *.doc for MSWord documents) that determines which
files display when that filter is selected. The first filter-pair in wTypeList
is the default.
This script is suitable for an action button or hotspot on a form, however, the
attachment will not show up on the document until after it has been saved and
' Paste the following line in the [Declarations] section of the Action
Declare Function NEMGetFile Lib "nnotesws" ( wHandle As Integer, Byval wName As
String, Byval wFilter As String, Byval wTitle As String ) As Integer
Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Dim ui As NotesUIDocument
Dim doc As NotesDocument
Dim rt As NotesRichTextItem
Dim wHandle As Integer
Dim wName As String*256
Dim wTypeList As String
Dim wDlgLabel As String
Dim wReturnedFile As String
' Assign parameter values
Set ui = ws.CurrentDocument
Set doc = ui.Document
If doc.HasItem("Attachments") Then
Set rt = doc.GetFirstItem("Attachments")
Set rt = New NotesRichTextItem(doc, "Attachments")
wHandle = 0
wName = "C:\"
wTypeList = "All files|*.*|Text files|*.txt"
wDlgLabel = "Attach File"
If NEMGetFile( wHandle, wName, wTypeList, wDlgLabel) <> 0 Then ' Returns 0
if user hits CANCEL
wReturnedFile = wName
Call rt.EmbedObject(EMBED_ATTACHMENT, "", wReturnedFile)