In Client 6.x attachments are NOT removed after using REMOVE method of NotesEmbeddedObject class

  1. I created agent for archiving attachments on storage server and then removing them from Notes documentHere is part of the code:

If Not Isempty(IMiSRTitem.EmbeddedObjects) Then

Forall IMiSObj In IMiSRTItem.EmbeddedObjects

If (IMiSObj.Type = EMBED_ATTACHMENT) Then

Call IMiSObj.Remove

Call IMiSMigDoc.Save(True,True)

End If

  1. I tested it on R4 - it works OK - attachments and their icons are removed

  2. I tested it on R5 - it works OK - attachments and their icons are removed

  3. I tested it on version 6 - it does not work OK - attachments and their icons are NOT removed. Attachments are “transfered” to the bottom of the document. It looks like only reference to RT item is removed with REMOVE method, but not attachment. It loolks like attachment “gets” V2 style.

So it seems like $FILE field is not removed in version 6. I do not want to handle and remove $FILE fields, so that is not solution for me. Recompiling the code on version 6 does NOT solve the problem.

Subject: Cause and workaround found

It looks like we can not use REMOVE method inside

Forall Item In Doc.Items

loop. After I extracted the code outside this loop, everything works fine.

So now I am just looking for RT items with attachments inside problematic loop, I write RT names in array and then I loop through this array to remove attachments. Here is the new code:

Dim IMiSSession As New NotesSession

Dim IMiSAttachmentsView As NotesView

Dim IMiSCollection As NotesDocumentCollection

Dim IMiSMigDoc As NotesDocument

Dim IMiSRTItem As NotesRichTextItem

Dim IMiSRTName As String

Dim IMiSItemtemp As NotesItem

Dim IMiSRTNames List As String

Dim i As Integer



Set IMiSAttachmentsView = IMiSSession.CurrentDatabase.GetView("IMiSAttachments")

If (IMiSAttachmentsView Is Nothing) Then

	Msgbox "Error opening 'IMiSAttachments' view in DB. View is nonexistent or unavailable."

	Exit Sub

End If



Set IMiSCollection = IMiSAttachmentsView.GetAllDocumentsByKey("1", False)

If IMiSCollection.Count = 0 Then

	Msgbox "No documents with attachments found."

	Exit Sub

End If



Set IMiSMigDoc = IMiSCollection.GetFirstDocument



While Not (IMiSMigDoc Is Nothing)

	i% = 0

	Forall IMiSItem In IMiSMigDoc.Items

		If IMiSItem.Type = RICHTEXT Then

			Set IMiSRTitem = IMiSMigDoc.GetfirstItem(IMiSItem.Name)

			If Not Isempty(IMiSRTitem.EmbeddedObjects) Then

				IMiSRTNames(i%) = Cstr(IMiSItem.Name)

				i% = i% +1

			End If

		End If

	End Forall

	

	For j% = 0 To i%-1 

		Set IMiRTItem = Nothing

		Set IMiSRTitem = IMiSMigDoc.GetfirstItem(IMiSRTNames(j%))

		Forall IMiSObj In IMiSRTItem.EmbeddedObjects

			If (IMiSObj.Type = EMBED_ATTACHMENT) Then

				Call IMiSObj.Remove

				Call IMiSMigDoc.Save(True,True)

			End If	

		End Forall 

	Next

IMiSNextDoc:

	Set IMiSMigDoc = IMiSCollection.GetNextDocument(IMiSMigDoc)

Wend

And again: This problem is only in 6.x version. R4 and R5 work fine.

Subject: RE: Cause and workaround found

I created an agent and copied your code into the initialize section. I created a view named IMiSAttachments copied from all documents view. When I run the agent I get the “No documents with attachments found.” message. What am i doing wrong?thanks

Milton

Subject: RE: Cause and workaround found

See last post on 12/16/2004

http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/fe7542cd3b120e1b00256c38004a6a27?OpenDocument&Highlight=0,detach

Subject: RE: Cause and workaround found

Would you be willing to tell me where to place this code? I’m not a developer/coder but I’m familair with Designer if you point me in the right direction. We did use the detach/remove and linnk agent before we upgraded to ND6.5. I’d love to be able to get it back to my users.Thanks in advance.

Subject: NotesEmbeddedObject.Remove and Forall. Another oddity and a workaround

Hi folks,

I was very grateful to find Mitja’s post and tried it in my application. Unfortunately it did not solve the problem; I was trying to remove file attachments from rich text fields using NotesEmbeddedObject.Remove(). Although the attachments disappeared from the rich-text field, they remained attached to the document itself. In the Notes client I could see this, because the attachments appeared in grey at the bottom of the form.

I stumbled upon a fix which I still do not quite believe; I removed ALL forall structures from the code, NOT ONLY the one in the loop that contains NotesEmbeddedObject.Remove()

In Mitja’s code there is a section that creates a list of rich-text fields, that uses a FORALL;

i% = 0

Forall IMiSItem In IMiSMigDoc.Items

If IMiSItem.Type = RICHTEXT Then

Set IMiSRTitem = IMiSMigDoc.GetfirstItem(IMiSItem.Name)

  If Not Isempty(IMiSRTitem.EmbeddedObjects) Then

     IMiSRTNames(i%) = Cstr(IMiSItem.Name)

     i% = i% +1

  End If

End If

End Forall

I replaced this with a clunkier loop that uses array subscripts and a dynamic array instead FORALL;

Dim nField As Integer

Dim aRTFields() As String

Redim aRTFields( 0 To 0 )

For nField = 0 To Ubound( doc.Items )

If doc.Items( nField ).Type <> RICHTEXT Then

  '  This field cannot have attachments, ignore it

Elseif Isempty( doc.Items( nField ).EmbeddedObjects ) Then

  '  no embedded objects in this richtext field 

Else

  '  This rich text field has one or more embedded objects, perhaps including file attachments

  '  Add it to our list

  If aRTFields( 0 ) <> "" Then

    Redim Preserve aRTFields( 0 To ( Ubound( aRTFields ) + 1 ) )

  End If

  aRTFields( Ubound( aRTFields ) ) = doc.Items( nField ).Name

End If

Next

and then the loop over the rich-text items goes;

For nField = 0 To Ubound( aRTFields )

Set rtItem = Nothing

Set rtItem = doc.GetFirstItem( aRTFields( nField ) )

’ … (now get the embedded objects in rtItem and remove any that are file attachments)

Next

When the code starting working after I introduced these changes, I thought I must be hallucinating and tried removing them again. The code stopped working. I re-introduced the changes and it worked again. So I don’t THINK I am imagining this, even though it seems completely illogical. This may be a funny that only affects my Notes client (version 6.5.2) or it could be strange side-effect in my application. Nonetheless I though I would post this in case it helps a fellow sufferer.

best wishes, Ian

Subject: See related posting …

See related posting …

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllThreadedweb/bb9318813b5084c085256ddb003d2031?OpenDocument

Subject: In Client 6.x attachments are NOT removed after using REMOVE method of NotesEmbeddedObject class

I came across this in the Knowledge Base, that you may give a try:

This issue was reported to Lotus Sofware Quality Engineering; however it was found that Notes Domino was functioning as designed.

In this particular case, the issue was resolved by reseting the NotesSession class’ ConvertMime property to True, which means the property must have been set to False by an earlier application and never reset to True. It is critical that any application which resets the ConvertMime property to False either on a server or locally resets the property back to True as the property is not otherwise reset unless Notes Domino is restarted.

The following code should work as expected:

            Dim session As New NotesSession

Dim doc As NotesDocument

Dim it As NotesItem

            session.convertmime=True

Set doc = session.documentContext

Set it = doc.getFirstItem("AttsToDelete")

Forall attName In it.values

	Set att = doc.GetAttachment(attName)

	Call att.Remove

End Forall

Call doc.replaceItemValue("AttsToDelete","")

Subject: RE: In Client 6.x attachments are NOT removed after using REMOVE method of NotesEmbeddedObject class

Thanks Greg, but it didnt help. I even tried it on 3 different databases, but no dofference, attachments still remain at the bottom of the document.