Hi there,
the following problem is keeping me busy.
I´ve got a document with three RichTextItems. Two of them could contain
an attachment that were attached by a user using the notes client.
The third one, with the name “RTFAttach”,
is generated by a scheduled agent.
This agent runs once a week and creates a new file to be attached under
“C:\temp\attach.pdf”.
Then the following piece of code is executed:
/* -------------------------------------------------- */
String nameOfPathToAttachment = “C:\temp\attach.pdf”;
String newNameOfAttachment = “attach.pdf”;
RichTextItem rti = null;
EmbeddedObject eos = null;
// delete the rtf/attachment from the document
rti = (RichTextItem) doc.getFirstItem(“RTFAttach”);
if (rti != null) {
eos = rti.getEmbeddedObjects();
for (int n = 0 ; n < eos.size() ; n++) {
eo = (EmbeddedObject) eos.elementAt(n);
if (eo != null && eo.getType() == EmbeddedObject.EMBED_ATTACHMENT) {
eo.remove();
}
}
rti.remove();
doc.save(true, false);
}
rti = (RichTextItem) doc.getFirstItem(“RTFAttach”);
if (rti == null) {
rti = doc.createRichTextItem("RTFAttach");
}
// attach the pdf to the document
rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, nameOfPathToAttachment, newNameOfAttachment);
doc.save(true, false);
/* -------------------------------------------------- */
after running it leaves the document “doc” with two $FILE items.
One contains an attachement called “attach.pdf”, the other one contains
a cryptic filename. Opening the document in notes client shows the newly
generated file “attach.pdf” in the correct place (the richtext item), and
another file - the old one - also with the name “attach.pdf” at the bottom
of the document.
Searching through the forums, tells me that that I´m doing the right steps
to avoid the problem with the “deleted attachment at the document bottom”.
Reality throws me back into a state of frustration.
Any suggestions?
Thankx in advance
Rolf