By
Published: 06 Apr 2001
This agent allows you to remove an attachment from a document. If you use the example in the Remove method under NotesEmbeddedObject in the help database, you will get an error if the object you are looking for does not exist. To get around this, the agent first creates an array of filenames of all attachments in the document. The agent then steps through the array of filenames and if the filename exists in the richtext field it is deleted. The error from the example will not happen in the agent because we're only looking for filenames that we know exist.
Dim s As NotesSession
Dim doc As NotesDocument
Dim db As NotesDatabase
Dim obj As NotesEmbeddedObject
Dim rt As NotesRichTextItem
Dim attachNames As Variant
Dim i As Integer
Set s = New NotesSession
set doc = ......
' --- create array of filenames of all the attachments in the document
i = 0
Redim attachNames(i)
Forall x In doc.items
If x.name = "$FILE" Then
attachNames(i) = x.values(0)
i = i + 1
Redim Preserve attachNames(i)
End If
End Forall
If i > 0 Then
Redim Preserve attachNames(i-1)
End If
' --- for all of the filenames in attachNames, if it exists in the rich text field, remove it
If doc.hasItem("body") Then
Set rt = doc.GetFirstItem("body")
End If
If attachNames(0) <> "" Then
Forall x In attachNames
Set obj = rt.GetEmbeddedObject( x )
If Not( obj Is Nothing ) Then
If ( obj.Type = EMBED_ATTACHMENT ) Then
Call obj.Remove
End If
End If
End Forall
End If
Call doc.save(True, False)
Dig Deeper on Domino Resources - Part 5