DoctorGonzo
Programmer
Hi all,
I am trying to create an agent to do the following and require some help if possible. I want to loop through a view and for each document check and detach the attachment.
The looping part I am OK with. And I have read the HELP on extractfile and just need come help tweaking this if possible. I have put the part where I need help in below as COMMENTS. It is the part below that says CODE HERE TO HANDLE ATTACHMENTS - this is the code from HELP, but I want to make 2 key changes to it
1) Keep the file names of the attachments the SAME as they are in the document
2) Before I detach the attachment, check if it exists in the specified folder, and if IT DOES, then save it in the \ERROR folder instead
AGENT :
Sub Initialize
' define my objects
Dim session As New notessession
Dim db As notesdatabase
Dim view As notesview
Dim doc As notesdocument, nextdoc As notesdocument,
Dim rtitem as variant
Dim fileCount As Integer
Set db = session.currentdatabase
' get handle to view
Set view = db.getview("InboundMail")
' loop through Database
Set doc = view.getfirstdocument
Do While Not(doc Is Nothing)
Set nextdoc = view.getnextdocument(doc)
' code here to handle attachments - NEED HELP WITH THIS PART PLEASE....
fileCount = 0
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
fileCount = fileCount + 1
' DOES FILE of this name exist c:\reports? if it DOES, save it in c:\errors
' ALSO, keep the filneame - do not call it newfile_x
I think this is the line/section that needs changing---> Call o.ExtractFile ( "c:\reports\newfile" & Cstr(fileCount) )
Call o.Remove
Call doc.Save( True, True )
End If
End Forall
End If
Set doc = nextdoc
Loop
End Sub
Many thanks all - I hope this is clear
Gonzo
I am trying to create an agent to do the following and require some help if possible. I want to loop through a view and for each document check and detach the attachment.
The looping part I am OK with. And I have read the HELP on extractfile and just need come help tweaking this if possible. I have put the part where I need help in below as COMMENTS. It is the part below that says CODE HERE TO HANDLE ATTACHMENTS - this is the code from HELP, but I want to make 2 key changes to it
1) Keep the file names of the attachments the SAME as they are in the document
2) Before I detach the attachment, check if it exists in the specified folder, and if IT DOES, then save it in the \ERROR folder instead
AGENT :
Sub Initialize
' define my objects
Dim session As New notessession
Dim db As notesdatabase
Dim view As notesview
Dim doc As notesdocument, nextdoc As notesdocument,
Dim rtitem as variant
Dim fileCount As Integer
Set db = session.currentdatabase
' get handle to view
Set view = db.getview("InboundMail")
' loop through Database
Set doc = view.getfirstdocument
Do While Not(doc Is Nothing)
Set nextdoc = view.getnextdocument(doc)
' code here to handle attachments - NEED HELP WITH THIS PART PLEASE....
fileCount = 0
'...set value of doc...
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
fileCount = fileCount + 1
' DOES FILE of this name exist c:\reports? if it DOES, save it in c:\errors
' ALSO, keep the filneame - do not call it newfile_x
I think this is the line/section that needs changing---> Call o.ExtractFile ( "c:\reports\newfile" & Cstr(fileCount) )
Call o.Remove
Call doc.Save( True, True )
End If
End Forall
End If
Set doc = nextdoc
Loop
End Sub
Many thanks all - I hope this is clear
Gonzo