Copy Attachment

Hi All,CopyItemToDocument copies all the attachments in a richtext field to another document. Can it be in done such a way, so that for each attached file there will be a seperate document?

For eg. if a richtext field has 3 attached files, the agent must remove these files and create 3 seperate documents with one file attached in each.

Subject: Copy Attachment

Hi Sandip

Here is a bit of code that is close to what you need. It compiles OK (I can save it as a Sub without errors) but I haven’t tested it.

You may have to do a little bit of adjustment to it as well as set the value of your document.

Dim session As New NotesSession

Dim db As Notesdatabase

Dim doc As NotesDocument, docNew As NotesDocument

Dim rtitem As Variant

Dim newItem As NotesRichTextItem

'…set value of doc… and set a loop to go through all the documents that you want to treat

Set rtitem = doc.GetFirstItem( "YourSourceFieldName" )		'Pointer to the richtext field storing the attachments

If ( rtitem.Type = RICHTEXT ) Then

	Forall o In rtitem.EmbeddedObjects					'Loop thru all the embedded objects in the field

		If ( o.Type = EMBED_ATTACHMENT ) Then

			Set docNew = db.CreateDocument()		'Your new documents that contain each of the attachments

			Set newItem = New NotesRichTextItem(docNew, "YourTargetFieldName") 'Pointer to your target field

			Call o.ExtractFile( "c:\YourTempDirectory\" & o.Source )		'Detach to disk, one by one

			Call newItem.EmbedObject( EMBED_ATTACHMENT, "", "c:\YourTempDirectory\" & o.Source)		'For this method to work you must set a default view in the database.

			Kill "c:\YourTempDirectory\" & o.Source

			docNew.Form = "any suitable form name here" 		'Don't forget to set the form etc

			Call docNew.Save( False, True )		'Save the new document

		End If

	End Forall

End If

Good luck

Bizhan

http://www.Internet-Marketing-Wizards.com

Subject: RE: Copy Attachment

Hi Bizhan,I tried this , but this is used only to extract file to the local machine. This does not work when I am trying to create a seperate documents for each attachment in Lotus Notes.

Subject: RE: Copy Attachment

Hi Sandip

Although you don’t mention it specifically, it sounds like you want to do this automatically on a ‘server’.

A variation of this code will work. You’ll have to see why it didn’t work before. For example, in the OS you need to have the right to create files on disk and access them and also to delte them after attaching.

I have used variations of this method in other server based apps … so don’t give up.

Good luck

Bizhan

http://www.Internet-Marketing-Wizards.com

Subject: RE: Copy Attachment

Hi Bizan,Thank you, I do want to do this automatically in the server. The agent must search for attachments in a richText filed named “Price” , copy all the attached files, generate a single document containing one file only. eg. If there are two files A , B , the agent will generate two docs., one containing the file A and the other file B. I do not want it to get extracted to the local machine.

Subject: Copy Attachment

Hello

Try using the EmbeddedObjects property of NotesRichtext item . An example is given in the Designer help file to get the attachments , u can then manipulate the code as per ur requirements.

HTH

Tom

Subject: RE: Copy Attachment

Hi Tom,

I tried the EmbeddedObjects property, but the ExtractFile can only be used while extracting the file to the local machine. But I want to create a document each for the attachments. Is there any other way?

Subject: RE: Copy Attachment

If the rich-text field contains three attachments copy the document three times.

On the first copy, remove attachments two and three.

On the second copy remove attachments one and three.

etc.

Frunobulax.