Manage Learn to apply best practices and optimize your operations.

Attaching And Detaching Files

This following function will detach all the attachements from a specified
document to a specified path and the other function will attach all the file
specified in the file list to a RTF item.
Function GetAllAttachments ( Doc As Notesdocument, Path As String , OutFiles As
Variant ) As Integer
' This function detaches all the File Attachments in the input Doc and
stores them in the path specified (if incorrect it saves in c:\temp)
' It returns 0 if not attachements found
' else it returns the number of attachements in the documents also all the
detached file names will be stored in the parameter string Outfiles
On Error Goto ErrorPara
If path = "" Then
path = "C:\Temp\"
Elseif Instr(path,":") = 0 Then
path = "C:\Temp\"
Elseif Instr(path,"\") = 0 Then
path = "C:\Temp\"
Elseif ( Right(path,1) <> "\" ) Then
path = "C:\Temp\"
Elseif Mid(path , 2 , 2) <> ":\" Then
path = "C:\Temp\"
End If

OutFiles = ""
GetAllAtachments = 0
If Not ( Doc.HasEmbedded) Then
Exit Function
End If

Dim n As Integer
Dim flname As String
n = 0
flname = ""
Dim rtitem As Variant

Forall Item In doc.items
If item.Type = RICHTEXT Then
If Not ( Isempty(item.EmbeddedObjects) ) And Not (
Isnull(item.EmbeddedObjects) ) Then
Forall o In item.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
n = n+1
Print "Detaching File # " + Cstr(n) + " : " +
Call o.ExtractFile( Path & o.Source )
flname = flname + Path+Cstr( +";"
End If
End Forall
End If
End If
End Forall

OutFiles = Evaluate(|@Explode("|+flname+|" ; ";")|)
GetAllAttachments = n
Print Cstr(n) + " files have be detached !"
Exit Function


Print " Error Occured in GetAllAttachments : " + Cstr(Err())+ Error$
Exit Function

End Function
Function PutAllAttachments ( RTItem As NotesRichTextItem , FileList As Variant,
DelFiles As Integer ) As Integer
' This function attaches the files whose names are specified in the
FileList into the RTItem which are passed as parameter
' If success it returns 1 else 0
' If DelFiles is 1 all the files that are attached will be removed from
the hard disk
On Error Goto ErrorPara

Dim object As NotesEmbeddedObject
Forall fname In FileList
Set object = RTItem.EmbedObject( EMBED_ATTACHMENT, "",
If ( DelFiles = 1 ) Then
Kill (fname)
End If
End Forall
PutAllAttachments = 1
Exit Function

Print " Error Occured : " + Error$
PutAllAttachments = 0
Exit Function

End Function

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...