Solved

Moving $File Attachments

Posted on 2001-07-12
13
315 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
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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