Lotus Notes GetAttachment Fails When Name Has Slashes

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
AlphaGuysAsked:
Who is Participating?
 
qwaleteeConnect With a Mentor Commented:
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
 
AlphaGuysAuthor Commented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
AlphaGuysAuthor Commented:
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
 
qwaleteeCommented:
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
 
AlphaGuysAuthor Commented:
Don't believe you can use the Evaluate function from VB
0
 
qwaleteeCommented:
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
 
qwaleteeCommented:
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
 
AlphaGuysAuthor Commented:
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
 
AlphaGuysAuthor Commented:
Thanks qwaletee
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.