How to display Create Attachment Dialog box using LotusScript

Hi,I have to hide the rich text field which is used for the attachment, so I can not use @Command( [EditInsertFileAttachment] ) to attach a file. How to do the following using LotusScript?

  1. Display a Create Attachment Dialog box like the one opened by the @Command( [EditInsertFileAttachment] ) for the user to pick a file.

  2. Get the user’s selection and attach the file to the document

Any help will be appreciated!

Jian

Subject: How to display Create Attachment Dialog box using LotusScript

Hi Jian-This will do it:

'paste into declarations

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)

On Error Goto End_Routine

Dim s As New NotesSession

Dim db As NotesDatabase

Set db = s.currentdatabase

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

Dim ws As New NotesUIWorkspace

Dim MessageText As String

’ Assign parameter values

Set ui = ws.CurrentDocument

Set doc = ui.Document

If doc.HasItem(“Attachments”) Then

Set rt = doc.GetFirstItem(“Attachments”)

Else

Set rt = New NotesRichTextItem(doc, “Attachments”)

End If

wHandle = 0

wName = Left((Trim(s.getEnvironmentString(“Directory”, True))),3)

wTypeList = “All files|.|Acrobat files|.pdf|Word files|.doc|Excel files|.xls|Text files|.txt”

wDlgLabel = “Attach File”

If NEMGetFile( wHandle, wName, wTypeList, wDlgLabel) <> 0 Then

’ Returns 0 if user hits CANCEL

Call ui.Save

unid = doc.UniversalID

wReturnedFile = wName

Call rt.EmbedObject(EMBED_ATTACHMENT, “”, wReturnedFile)

Call doc.Save(True, True, True)

Call ui.Reload

Call ui.Save

Call ui.Close(True) ’ Parameter closes immediately

Set doc = Nothing ’ Clear the variable so Notes will not cache it

Set doc = db.GetDocumentByUNID(unid) ’ Reset the handle

Call ws.EditDocument(True, doc) ’ Reopen the document

End If

End_Routine:

Exit Sub

End Sub

Subject: RE: How to display Create Attachment Dialog box using LotusScript

Stan,

Thanks a lot…!! Your response is very helpful.

I changed “Attachments” in your script to the name of my rich text field as follows:

If doc.HasItem(“InforAttach”) Then

Set rt = doc.GetFirstItem(“InforAttach”)

Else

Set rt = New NotesRichTextItem(doc, “InforAttach”)

End If

It worked pretty good except the attachment was attached to the bottom of the form instead of the “InforAttach” field I specified.

I do not understand why the attachment was embedded at the bottom?

Jian

Subject: NotesUIWorkspace.OpenFileDialog