Problems deleting a particular attachment and attaching another of the same name

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

Subject: Problems deleting a particular attachment and attaching another of the same name …

I’ve found in the past that after deleting the attachment & saving, I had to reset the doc object and then attach the new itemI think I maght have have set the doc to Nothing as well - can’t remember exactly

Subject: RE: Problems deleting a particular attachment and attaching another of the same name …

Thank you Christopher - quick response :slight_smile:

but even adding the lines /* ## … ## */ below

did not solve the problem :frowning:

/* -------------------------------------------------- */

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");

}

/* ############### NEW #################### */

String docIdToSave = doc.getUniversalID();

doc = null;

doc = db.getDocumentByUNID(docIdToSave);

/* ############### END NEW #################### */

// attach the pdf to the document

rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, nameOfPathToAttachment, newNameOfAttachment);

doc.save(true, false);

/* -------------------------------------------------- */

Subject: RE: Problems deleting a particular attachment and attaching another of the same name …

Hmmm - sorry then, that’s all I an dredge out of my memoryAs I’m sure you’ve realised, Noes still thinks there’s an attachment with the ‘old’ name and so builds a strange name for the new attachment

I can’t remember how I got around that, sorry. 8-(

Subject: RE: Problems deleting a particular attachment and attaching another of the same name …

Just reread - is Null the same as Nothing in lotusscript?I thought Nothing had a particular meaning

Subject: RE: Problems deleting a particular attachment and attaching another of the same name …

Hi Christopher,

Just reread - is Null the same as Nothing in lotusscript?

I hope so, setting an object variable to null in Java means that it isn´t holding a valid object reference. After doing this I recreate the object´s reference by db.getDocumentByUNID()

I thought Nothing had a particular meaning

Sometimes it seems to me that almost everything in LotusScript has some kind of a “particular meaning” :slight_smile:

that´s why I prefer using Java

Many thanks for the effort you made, I´ll go on trying to solve the prob.

Cheers

Rolf

Subject: *Almost everything in Java has a particular meaning too, but it is just a different set of meanings

Subject: RE: *Almost everything in Java has a particular meaning too, but it is just a different set of meanings

Hi,

:slight_smile:

Did you read the whole thread? I know that you are an expert concerning Notes and especially RichText probs.

Did you encounter this too, and is there a solution or at least an approach to this prob without using Midas-Tools ?

Greetings

Rolf