Solved

Deleting an attachment

Posted on 2002-07-04
17
262 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now