Solved

Deleting an attachment

Posted on 2002-07-04
17
266 Views
Last Modified: 2013-12-18
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.
0
Comment
Question by:koray_uygun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
17 Comments
 
LVL 10

Expert Comment

by:zvonko
ID: 7129605
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
 

Author Comment

by:koray_uygun
ID: 7129681
How can i "recreate the RT field completely"?
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7129915
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 10

Expert Comment

by:zvonko
ID: 7129920
Sorry, NewLine should be in a new line :)

0
 

Author Comment

by:koray_uygun
ID: 7129958
At this line :
Set rtitem = doc.CreateRichTextItem("Body")
the debugger says that the Body rich text item already exists.
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7130020
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
 
LVL 10

Expert Comment

by:zvonko
ID: 7131204
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
 

Author Comment

by:koray_uygun
ID: 7131237
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
 

Author Comment

by:koray_uygun
ID: 7131256
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
 
LVL 10

Accepted Solution

by:
zvonko earned 100 total points
ID: 7131570
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
 
LVL 10

Expert Comment

by:zvonko
ID: 7131574
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
 

Author Comment

by:koray_uygun
ID: 7131757
SorryZvonko but at that line :
Set rtitem= doc.CreateRichTextItem("PhotAtt")

it still does not want to create another rtitem PhotAtt.
0
 

Author Comment

by:koray_uygun
ID: 7131760
And i have looked, there's only one PhotAtt item in the document.
0
 
LVL 10

Expert Comment

by:zvonko
ID: 7131844
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
 

Author Comment

by:koray_uygun
ID: 7131924
;-)
0
 

Author Comment

by:koray_uygun
ID: 7132437
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
 
LVL 10

Expert Comment

by:zvonko
ID: 7132900
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question