Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Moving $File Attachments

Posted on 2001-07-12
13
Medium Priority
?
323 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 1200 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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