Solved

Lotus Notes GetAttachment Fails When Name Has Slashes

Posted on 2007-11-28
10
1,807 Views
Last Modified: 2013-12-18
Set oAttachment = oDoc.GETATTACHMENT(myValues(0)) fails when the attachment name has slashes.
When asking for the NotesItem.Values property it returns name as "myfile.pdf" which causes an error when calling oDoc.GETATTACHMENT(myValues(0))

When looking at that attachment name from within lotus notes the name is actually /someDirectory/anotherDirectory/myfile.pdf

How do I retrive the correct attachment name ?

We are using VB6 and Lotus Notes 6


  Dim oAttachment As Object
  Dim oItem As Object
  Dim i
  Dim myItems, myValues
  Dim filename As String, strFinalPath As String
     
  If oDoc.hasEmbedded Then

    myItems = oDoc.Items

     For i = UBound(myItems) To 0 Step -1
                                           
                                           
      Set oItem = myItems(i)
     
     
      If oItem.Type = 1084 Then ' Attachment
               
        myValues = oItem.Values
        Set oAttachment = oDoc.GETATTACHMENT(myValues(0))
       
        filename = CStr(oAttachment.Name)
      oAttachment.EXTRACTFILE strFinalPath & "\" & filename
     
      end if

     loop

   end if
0
Comment
Question by:AlphaGuys
  • 5
  • 4
10 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 20371019
0
 

Author Comment

by:AlphaGuys
ID: 20372421
Hi,
Thanks for the links but they do not address my issue.
Regardless of which method I call it does not return entire attachment filename when it has slashes "/" in the name.

myValues = oItem.Values
Set oAttachment = oDoc.GETATTACHMENT(myValues(0))
the first element of oItem.Values returns "myfile.pdf" where it should return "sometext/myfile.pdf"

0
 

Author Comment

by:AlphaGuys
ID: 20373885
Addional info:

I just created an Agent in Notes:
arrFileNames = Evaluate("@AttachmentNames", doc)

This returns the correct filename, BUT....I need to do it from VB
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 31

Expert Comment

by:qwaletee
ID: 20377872
You can use

fileNames = NotesSession.Evaluate("@AttachmentNames")

to retrieve an array of the attachment internal filenames.

Also, you can just iterate over all the NotesEmebeddedObject elements.
0
 

Author Comment

by:AlphaGuys
ID: 20378064
Don't believe you can use the Evaluate function from VB
0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20378177
Actually, I see you already iterate over the items.  If you are doing that, thn you don't need .GetAttachment.  For a document with a normally-named attachment (without the odd file name), the following two objects will have identical results:


Dim fileA As Object ', fileB As Object 'fileB does not need to be decalred since it in a For Each target
 
Dim oItem As Object
Dim i
Dim myItems, myValues
Dim filename As String, strFinalPath As String
myItems = oDoc.Items
For i = UBound(myItems) To 0 Step -1 
  Set oItem = myItems(i)
  If oItem.Type = 1084 Then ' Attachment 
    myValues = oItem.Values
    Set fileA = oDoc.GETATTACHMENT(myValues(0))
    'you could now do fileA.extractFile
  End If
  'Now get the same object in a different way
  If oItem.type = 1 Then 'rich text
    If IsArray(oItem.EmbeddedObjects) Then
      For Each fileB in oItem.EmbeddedObjects
        'you could now do fileB.extractFile
      Next
    End If
  End If
Next
 
 
The advantage here is that you do not have to use Evaluate to figure out what file name to use.

Open in new window

0
 
LVL 31

Expert Comment

by:qwaletee
ID: 20378188
Lotus provides two different Evaluate functions/methods:

1) Built in to LotusScript, not accessible to VB

2) A method of the NotesSession object in COM, specifically so VB (or other COM clients) can do an Evaluate
0
 

Author Comment

by:AlphaGuys
ID: 20380798
Thanks qwaletee,
So when I use the second method I assume I will get the same number of files as using the first method ?

will oItem.EmbeddedObjects ever return a count > 1 ?

'Now get the same object in a different way
If oItem.type = 1 Then 'rich text
    If IsArray(oItem.EmbeddedObjects) Then
      For Each fileB in oItem.EmbeddedObjects
        'you could now do fileB.extractFile
      Next
    End If
  End If
0
 
LVL 31

Accepted Solution

by:
qwaletee earned 500 total points
ID: 20382405
Yes, EmbeddedObjects in a rich text field is an array of all the items emedded in the field. The FOr Each runs through the array.

Note: There is a situation where there could be an attahced file that is not in any NotesRichTextItem.EmbeddedObjects. Sometimes, objects are mebedded directly into the document without being contained by any field.  But you can get the same code to run:

   If IsArray(oDoc.EmbeddedObjects) Then
      For Each fileB in oDoc.EmbeddedObjects
        'you could now do fileB.extractFile
      Next
    End If


So, you might create a sub to do both:


Sub ExtractAllFiles(container, targetPath As String)
   If IsArray(container.EmbeddedObjects) Then
      For Each oFile in container.EmbeddedObjects
         oFile.extractFile targetPath + "\" + oFile.Source
      Next
    End If
End Sub
 
'Now we can call that on each rich text item and on the doucment itself
 
For Each notesItem In oDoc.Items
  If notesItem.type = 1 'rich text can have objects in it
    Call ExtractAllFiles(notesItem,strFinalPath)
  End If
Next
Call ExtractAllFiles(oDoc,strFinalPath)

Open in new window

0
 

Author Comment

by:AlphaGuys
ID: 20404767
Thanks qwaletee
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

777 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