Solved

Moving $File Attachments

Posted on 2001-07-12
13
316 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
[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
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 13

Expert Comment

by:CRAK
ID: 6279767
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
ID: 6279794
I did what CRAK suggested before. It worked.
0
 
LVL 10

Accepted Solution

by:
zvonko earned 300 total points
ID: 6281343
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:CRAK
ID: 6284101
That's dirty!
Love it!
0
 
LVL 1

Author Comment

by:pcorreya
ID: 6284339
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
ID: 6284612
Hey Patrick,

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

Regards,
zvonko
0
 
LVL 1

Author Comment

by:pcorreya
ID: 6285389
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
ID: 6285418
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
ID: 6288001
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
ID: 6293323
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
ID: 6299944
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
ID: 6300868
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
ID: 6302687

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Lotus Notes 41 223
If no attachment, dont send email - lotus notes/vba 10 396
Lotus Domino Server 9 4 98
Domino/Lotus Notes form, showing list of values based on a condition 3 79
For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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