Deleting an attachment

Hi,
i want to attach a picture to a document that contains a richtext field but before i must check if there is already one, if yes, i have to delete the old picture and attach another one. Does some one has the code to detect and delete this attacment if it exists?

Thanks,
Koray.
koray_uygunAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
zvonkoConnect With a Mentor Commented:
Sorry,

change this:
If (PhotoFileNames <> "") Then
     Set rtpers=docpers.getfirstitem("PhotAtt")
     Call rtpers.Remove
     Set rtitem= doc.CreateRichTextItem("PhotAtt")
     Do While (PhotoFileNames > "")
                       '          Set object=rtitem.EmbedObject( EMBED_ATTACHMENT, "", Strleft(PhotoFileNames, ";"))
          Set object=rtitem.EmbedObject( EMBED_ATTACHMENT, "", "c:\temp\"&Ucase(o.name) )
   '       PhotoFileNames = Strright(PhotoFileNames, ";")
     Loop
End If

to this:
If (PhotoFileNames <> "") Then
  Delete rt
  Set item=docpers.getfirstitem("PhotAtt")
  Call item.Remove
  Set rtitem= doc.CreateRichTextItem("PhotAtt")
  Do While (PhotoFileNames > "")
    Set object=rtitem.EmbedObject( EMBED_ATTACHMENT, "", Strleft(PhotoFileNames, ";"))  
    PhotoFileNames = Strright(PhotoFileNames, ";")
  Loop
End If

declare this new item in header section like this:
Dim item As NotesItem

This declaration is then obsolete:
Dim rtpers As notesrichtextitem

Sorry that I can not test this in advance. It is much less work when you test it opposite when I have to simulate it.

Tell me the next effects.

So long,
zvonko


0
 
zvonkoCommented:
Attached objects can be deleted by removing $FILE items from the document. First value in this $FILE items is the attachment file name.

But this does not render the RichText field image. You have still an attachment icon without an attachment behind it.

Why is it not possible to recreate the RT field completely?

0
 
koray_uygunAuthor Commented:
How can i "recreate the RT field completely"?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
zvonkoCommented:
Set item = doc.GetFirstItem("Body")
Call item.Remove
Set rtitem = doc.CreateRichTextItem("Body")
Call rtitem.AppendText("Book for Developer ages 19-91" )Call rtitem.AddNewLine(1)
Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", "c:\book.pdf")


You see?

0
 
zvonkoCommented:
Sorry, NewLine should be in a new line :)

0
 
koray_uygunAuthor Commented:
At this line :
Set rtitem = doc.CreateRichTextItem("Body")
the debugger says that the Body rich text item already exists.
0
 
zvonkoCommented:
After this two lines it can not be true:
Set item = doc.GetFirstItem("Body")
Call item.Remove


Can you send me your script so far to paunoski@freenet.de

0
 
zvonkoCommented:
Hello Koray,

did you got my email?
I had to guess your email from Notes sender address, so please send your internet email address if you did not got at least one email from me.

So long,
zvonko
0
 
koray_uygunAuthor Commented:
Hi, thanks for your mail Zvonko. I am working on 4.6 version so i think that's why notes doesn't understand strleft or strright command in the script... :-(
What does this command do?
0
 
koray_uygunAuthor Commented:
So here what i've done:

                    PhotoFileNames = ""
                    If doc.hasembedded Then
                         Set rt=doc.getfirstitem("PhotAtt")
                         Forall ob In rt.embeddedobjects
                              If ob.type=embed_attachment Then
                                   PhotoFileNames = PhotoFileNames & "c:\temp\"&Ucase(ob.name) & ";"
                                   Call ob.extractfile("c:\temp\"&Ucase(ob.name))
                              End If
                         End Forall
                         If (PhotoFileNames <> "") Then
                              Set rtpers=docpers.getfirstitem("PhotAtt")
                              Call rtpers.Remove
                              Set rtitem= doc.CreateRichTextItem("PhotAtt")
                              Do While (PhotoFileNames > "")
                        '          Set object=rtitem.EmbedObject( EMBED_ATTACHMENT, "", Strleft(PhotoFileNames, ";"))
                                   Set object=rtitem.EmbedObject( EMBED_ATTACHMENT, "", "c:\temp\"&Ucase(o.name) )
                            '       PhotoFileNames = Strright(PhotoFileNames, ";")
                              Loop
                         End If
                         docpers.PhotoName=doc.PhotoName(0)
                    End If

And it says still the same thing that the RichText Item PhotAtt already exists...
0
 
zvonkoCommented:
Oh,

one more thing to check...

Look in such a document where PhotAtt has to be removed how much PhotAtt items are currently present in this document. They could be more then one.

Best to see is this in document property dialog in Notes client.

0
 
koray_uygunAuthor Commented:
SorryZvonko but at that line :
Set rtitem= doc.CreateRichTextItem("PhotAtt")

it still does not want to create another rtitem PhotAtt.
0
 
koray_uygunAuthor Commented:
And i have looked, there's only one PhotAtt item in the document.
0
 
zvonkoCommented:
OK, then I have to simulate...

But this takes a while :)

Meanwhile perhaps other experts around here can have a look.

So long,
zvonko

0
 
koray_uygunAuthor Commented:
;-)
0
 
koray_uygunAuthor Commented:
This works Zvonko!! I am so stupid, i have made a mistake in the code here :
 Set item=docpers.getfirstitem("PhotAtt")
 Call item.Remove
 Set rtitem= doc.CreateRichTextItem("PhotAtt")

The third line is not good, it must be :
 Set rtitem= docpers.CreateRichTextItem("PhotAtt")

So thanks for all!!
0
 
zvonkoCommented:
Don't tell "stupid"
'cause I am this then too, repeating your mistake :)

Thanks for the points and for funny working together.

'till next time,
zvonko
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.