Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next

Re: copy attachments

Hi,

You can detach all attachments from Doc1 to a folder on the machine where code is running and attach them back to individual documents in the other database.

Here's a sample code to detach files to local machine and maintain a list of them. Afterwards, you will need to process the list of file paths and attach the attachments back into the target documents.

Part 1 of your solution:
Function DetachFilesForSubmit(requestdoc As NotesDocument, detachedfile_lst List As String) As Boolean

Dim origfileatt_lst List As NotesEmbeddedObject
Dim detachpath As String
Dim submitlocalfile As String

'Initialize
On Error GoTo errorhandler

If getAttachmentObjectList(requestdoc, origfileatt_lst) then
ForAll origfileatt In origfileatt_lst
'Getting path to temporarily detach file, in this case it is obtained from a profile doc
detachpath$ = requestdoc.parentdatabase.GetProfileDocument( "Configuration" ).FileToTransmitDir(0)
If Right(detachpath$,1)<>"\" Then detachpath$=detachpath$+"\"
submitlocalfile$=detachpath$+origfileatt.source
'Save file temporarily to disk
Call origfileatt.extractfile(submitlocalfile$)
detachedfile_lst(origfileatt.Name)=submitlocalfile$
End ForAll
End if

DetachFilesForSubmit=True
Exit Function
errorhandler:
DetachFilesForSubmit=False
Msgbox "Error " + CStr(Err()) + " in function DetachFilesForSubmit: " + Error()
Exit Function
End Function

Function getAttachmentObjectList(doc As NotesDocument, outlst_att List As NotesEmbeddedObject) As Boolean

On Error GoTo errorhandler

Dim catt As Variant, natt As Variant
Dim att As NotesEmbeddedObject

'Get number of attached files
catt=Evaluate("@attachments",doc)

'If no files are attached, return
If CInt(catt(0))=0 Then
errorevent$="Error: No file attachment in document"
Exit Function
End If

'Get attachment names
natt=Evaluate("@attachmentnames",doc)
ForAll attname In natt
'Check file type and include only valid file in list
Set att=doc.getattachment(attname)
If not att Is Nothing Then
If att.type=EMBED_ATTACHMENT Then
Set outlst_att(att.Name)=att
End If
End If
End ForAll

getAttachmentObjectList=True
Exit Function
errorhandler:
getAttachmentObjectList=False
msgbox "Error " + CStr(Err()) + " in function getAttachmentObjectList: " + Error()
End Function

Part 2:
Dim obj As NotesEmbeddedObject

'detachedfile_lst is the output parameter of DetachFilesForSubmit
'call DetachFilesForSubmit to extract the files to local and prepare the list of file path
ForAll filepath In detachedfile_lst
'Create a NotesDocument

'Create a rictextitem in the document

'attach file to richtext
Set obj=body.embedobject(EMBED_ATTACHMENT,"",filepath)
Print "Deleting file "+filepath
Kill filepath
End ForAll

Hope this helps.


Feedback response number WEBB8LNLDN created by ~Wendy Zentookonyetsi on 09/13/2011

copy attachments (~Autumn Elboosi... 13.Sep.11)
. . Re: copy attachments (~Wendy Zentooko... 13.Sep.11)
. . . . Thanks (~Autumn Elboosi... 13.Sep.11)
. . . . Attach/detach - thanks! (~Umberto Quetwe... 16.Oct.12)




Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS