Problem to export attachments

HelloI want to mark one or more documents in a view, and export any files to a predetermined location on the server. What happens is that if i choose more than one document, so nothing is exported. What am I missing.

Sub Initialize

Dim session As NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim body As NotesRichTextItem

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

If Not doc.HasEmbedded Then Exit Sub

Set body = doc.GetFirstItem("Body")

REM Get attachments

Forall att In body.EmbeddedObjects

	If att.Type = EMBED_ATTACHMENT Then

		filepath$ = "C:\temp\export\" & att.Source

		Call att.ExtractFile(filepath$)

		Print filepath$ & " extracted"

	End If

End Forall

End Sub

Kind regards

Fredrik

Subject: Problem to export attachments

Hello Fredrik Schotte,

I have tweaked your code for exporting attachments from the multiple documents. here it is…

Sub Initialize

Dim session As NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim body As NotesRichTextItem

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument	

While Not doc Is Nothing

	If Not doc.HasEmbedded Then

		Set body = doc.GetFirstItem("Attach")				

		Forall att In body.EmbeddedObjects

			cnt=cnt+1

			If att.Type = EMBED_ATTACHMENT Then

				filepath$ = "C:\temp\export\" & att.Source

				Call att.ExtractFile(filepath$)

				Print filepath$ & " extracted"

			End If

		End Forall

	End If

	Set doc=dc.GetNextDocument(doc)

Wend

End Sub

Thanks,

Sreedhar.

Subject: RE: Problem to export attachments

I think something is wrong. I use debugger but nothing happens. No files are attached.

Subject: RE: Problem to export attachments

Attach or Detach?

Try the code here:

http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/fe7542cd3b120e1b00256c38004a6a27?OpenDocument&Highlight=0,detach

Subject: RE: Problem to export attachments

Hello Fredrik,

added the Errorhandling block for the above code.

Sub Initialize

On Error Goto ErrorBlock

Dim session As NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim body As NotesRichTextItem

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument	

While Not doc Is Nothing

	If Not doc.HasEmbedded Then

		Set body = doc.GetFirstItem("Attach")				

		Forall att In body.EmbeddedObjects				

			If att.Type = EMBED_ATTACHMENT Then

				filepath$ = "C:\temp\" & att.Source 

				Call att.ExtractFile(filepath$)

				Print filepath$ & " extracted"

			End If

		End Forall

	End If

	Set doc=dc.GetNextDocument(doc)

Wend

Exit Sub

ErrorBlock:

Msgbox "Error is:" & Error() & " Error At:" & Erl

End Sub

and one more thing is check if the Agent Second tab properties for set runtime security level as third option.

good luck,

Sreedhar.