Last month we were creating a Workflow project for one of our clients in which we had to allow the Sales Engineer to create an initial request using a Web form, which would later be incorporated into Notes to pass thru various stages of approval. In this form, he was allowed to include attachments which had to be retrieved into the Notes document.

The issue that we faced was that when the attachment was uploaded into notes, it simply got appended below. To get over this and ensure that it was aligned properly in the rich Text field that we had specifically created for that purpose, we had to write code which I have specified below:

Function WebMoveAttachment(doc As NotesDocument, ByVal moveToFieldName As String)
Dim s As New NotesSession
Dim tempDir As String
Dim v2FileNames As Variant
Dim i As Integer
Dim attachedFile As NotesEmbeddedObject
Dim filePath As StringDim rtItem As NotesRichTextItem
tempDir = s.getEnvironmentString(“Directory”, True) ‘Getting the notes temp path|
‘ Put a trailing slash at the end of the directory if it is needed

If InStr(tempDir, “/”) <> 0 And Right(tempDir, 1) <> “/” Then tempDir = tempDir & “/”
If InStr(tempDir, “”) <> 0 And Right(tempDir, 1) <> “” Then tempDir = tempDir & “”
‘ Get the names of all the attachments (1 or more)
v2FileNames = Evaluate(“@AttachmentNames”, doc)
For i = LBound(v2FileNames) To UBound(v2FileNames)
If v2FileNames(i) <> “” Then ‘ Make sure it’s a valid file name
Set attachedFile = doc.getAttachment(v2FileNames(i))
filePath = tempDir & v2FileNames(i)
‘ Save the file on the server
Call attachedFile.extractFile(filePath)
‘ Create the rich text item and re-attach the file
If doc.hasItem(moveToFieldName) Then
Set rtItem = doc.getFirstItem(moveToFieldName)
‘ Add a couple of lines to the rich text field before re-attaching the file
Call rtItem.addNewLine(2)
Set rtItem = New NotesRichTextItem(doc, moveToFieldName)
End If
Call rtItem.embedObject(1454, “”, filePath)
Call attachedFile.Remove()
‘ Call,False)
‘ Delete the file(s) from the server file system
Kill filePath
End If
Next ‘ Move on to the next file name
End Function

This is how you can retrieve a attachment from a web form and attach it to Lotus Notes.