Attach file to rich text field

In my document I had put a Rich Text field for file attachment. How to attach a file programmatically?(Provided the file path).

For other types (Text field for example) I can use replaceItemValue to assign the value. But it doesn’t work for rich text field. Here is my java agent example:

String field = “ExtraFile”; // field name

Item item = document.getFirstItem(field);

RichTextItem rit;

if (item == null) {

rit = doc.createRichTextItem(field);

}

else {

rit = (RichTextItem)item;

}

String filePath = “C:\Info.xls”;

rit.embedObject(EmbeddedObject.EMBED_ATTACHMENT, “”,filePath,“”);

document.replaceItemValue(field, rit);

There is an error “4263 Item value cannot be set to object of this type” when I run it.

Please advise. Thank you.

Subject: re: Attach

Dim session As New NotesSessionDim db As NotesDatabase

Dim doc As NotesDocument

Dim rtitem As NotesRichTextItem

Dim object As NotesEmbeddedObject

Set db = session.CurrentDatabase

Set doc = New NotesDocument( db )

Set rtitem = New NotesRichTextItem( doc, “Body” )

Set object = rtitem.EmbedObject _

( EMBED_ATTACHMENT, “”, “c:\jim.sam”)

doc.Form = “Main Topic”

doc.Subject = “Here’s Jim’s document, as an attachment”

Call doc.Save( True, True )