Solved

Moving $File Attachments

Posted on 2001-07-12
13
313 Views
Last Modified: 2013-12-18
I need to move each $File attachments from one document to multiple documents. I am currently using the code below to get hold of the attachment, but can't find a way to save it to the other document. Help in solving this problem will be greatly appreciated.

     Dim sesCurrent As New NotesSession
     Dim dbCurrent As NotesDatabase
     Dim docCurrent As NotesDocument
     Dim docRDdoc As NotesDocument
     Dim item As NotesItem
     Dim emb As Variant
     Set dbCurrent = sesCurrent.CurrentDatabase
     Set docCurrent = sesCurrent.DocumentContext
     Set docRDdoc  = dbCurrent.Createdocument
     Forall i In docCurrent.Items
          If i.type = Attachment Then
               Set emb = docCurrent.GetAttachment(i.values(0))
                 "HOW DO I STORE THE OBJECT to docRDdoc"              
          End If
     End Forall
     
0
Comment
Question by:pcorreya
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
Can't you detach the attachments automatically (using NotesEmbeddedObject.ExtractFile(path)), re-attach them in those other documents (Set notesEmbeddedObject = notesRichTextItem.EmbedObject( type%, class$, source$, [ name$ ] ) - see Help) and delete the detached files?
On a server, as an agent, you would need unrestricted access to do this!
0
 

Expert Comment

by:IceMountain
Comment Utility
I did what CRAK suggested before. It worked.
0
 
LVL 10

Accepted Solution

by:
zvonko earned 300 total points
Comment Utility
Hello pcorreya,

do it with a trick! <|;-)
Simply copy all items, and then delete or replace this items you like to have diferent.

Here your code for this:

Sub Initialize
  Dim sesCurrent As New NotesSession
  Dim dbCurrent As NotesDatabase
  Dim docCurrent As NotesDocument
  Dim docRDdoc As NotesDocument

  Set dbCurrent = sesCurrent.CurrentDatabase
  Set docCurrent = sesCurrent.DocumentContext
  Set docRDdoc  = dbCurrent.Createdocument
  Call docCurrent.CopyAllItems( docRDdoc, True )
  docRDdoc.Subject = "Only a copy"
  Call docRDdoc.RemoveItem( "AnyUnNeededField" )
  Call docRDdoc.Save(True, False)
End Sub

Regards,
zvonko
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
That's dirty!
Love it!
0
 
LVL 1

Author Comment

by:pcorreya
Comment Utility
CRAK,

These are not embedded attachments in richtext fields. They were attached from the web using the file upload control. The notesembeddedobject doesn't work for it.

I also tried the following code and get a type mismatch error.

Forall o in doc.embeddedobjects
   print o.name
End forall

Thanks
Patrick
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
Hey Patrick,

have you tried my trick? It works in any case, 'cose it's the way replication is working...

Regards,
zvonko
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Author Comment

by:pcorreya
Comment Utility
zvonko

Thanks for your comments, I would have used your trick if I was copying all attachments to another document. But I have to copy each $file attachment to seperate documents, that is the problem. Also, the document contains about 150 fields on it.

Thanks
Patrick
0
 
LVL 13

Expert Comment

by:CRAK
Comment Utility
This type mismatch that you when testing

Forall o in doc.embeddedobjects
  print o.name
End forall

Where does it occur?
If in the Print-line: was o aready DIMmed?
Is the "found" embedded object an attachment?
You have noticed that the property is not available on all platforms?
Or did you trigger it from an unsaved UIDoc?

What if you store @AttachmentNames in a Computed field and read that field in script: you could try:
Set notesEmbeddedObject = notesDocument.GetAttachment( fileName$ )
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
Hello Patrick,

I would say, this an extra 300 points answer ;-))

Use this:
'CopyAttachments:
Option Public
Option Declare

Sub Initialize
  Dim sesCurrent As New NotesSession
  Dim dbCurrent As NotesDatabase
  Dim docCurrent As NotesDocument
  Dim docRDdoc As NotesDocument
  Dim srcItem As NotesItem
 
  Set dbCurrent = sesCurrent.CurrentDatabase
  Set docCurrent = sesCurrent.DocumentContext
  Set docRDdoc  = dbCurrent.Createdocument
  Call docCurrent.CopyAllItems( docRDdoc, True )
  Forall  item In docCurrent.Items
    If ( item.Name <> "$FILE" ) Then
      Call docRDdoc.RemoveItem( item.Name )
    End If
  End Forall
  docRDdoc.Subject = "CopyOfAttachmentsOnly"
  Call docRDdoc.Save(True, False)
End Sub

One small note: the subject title is not totaly true. The reason is I do not realy check for item.Type == ATTACHMENT. So you get also OLE items with name $FILE copied. If this is also a problem for you, then open a NEW question for this; OK. <|;-)

I hope you are helpped now... ;-)
zvonko
0
 
LVL 1

Author Comment

by:pcorreya
Comment Utility
Hi zvonko

You did not ready my previous comment properly, I need to copy each attachment to a seperate document. If I wanted to copy all attachment to another document they your suggestion would work.

Thanks
Patrick

0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility
Hello Patrick,

this is realy the last try to get my points ;-)

So take this and give me an A <|;-)

Sub Initialize
  Dim sesCurrent As New NotesSession
  Dim dbCurrent As NotesDatabase
  Dim docCurrent As NotesDocument
  Dim docRDdoc As NotesDocument
  Dim docMOREdoc As NotesDocument
  Dim FileCount As Integer
  Dim FileNames List As String
 
  Set dbCurrent = sesCurrent.CurrentDatabase
  Set docCurrent = sesCurrent.DocumentContext
  Set docRDdoc  = dbCurrent.Createdocument
  '//now create a master copy
  FileCount = 0
  Call docCurrent.CopyAllItems( docRDdoc, True )
  Forall  item In docRDdoc.Items
    If ( item.Name <> "$FILE" ) Then
      Call docRDdoc.RemoveItem( item.Name )
    Else
      FileCount = FileCount + 1
      FileNames( FileCount ) = item.Values(0)
    End If
  End Forall
  '//now make copies and reduce to one attachment
  If (FileCount = 1) Then
    docRDdoc.Subject = "CopyOfAttachment: " & FileNames(1)
    Call docRDdoc.Save(True, False)  
  Elseif (FileCount > 1) Then
    Forall attname In FileNames
      Set docMOREdoc  = dbCurrent.Createdocument
      Call docRDdoc.CopyAllItems( docMOREdoc, True )
      Forall  item In docMOREdoc.Items
        If ( item.Values(0)  <> attname ) Then Call item.Remove
      End Forall
      docMOREdoc.Subject = "CopyOfAttachment: " & attname
      Call docMOREdoc.Save(True, False)  
    End Forall
    Delete docRDdoc '//not realy necessary
  End If
  '//job done
End Sub

Good luck,
zvonko
0
 
LVL 1

Author Comment

by:pcorreya
Comment Utility
zvonko

Quite a nifty solution, it works. I give you full credit for this. Thanks for your perseverance, people like you who give it a 100% to find a solution is a reason why this site is so popular. It is a pity that Notes doesn't make it easy to do a simple operation like this.

Regards
Patrick
0
 
LVL 10

Expert Comment

by:zvonko
Comment Utility

Thank you Patrick  for the points and for the feedback <|;-)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

8 Experts available now in Live!

Get 1:1 Help Now