?
Solved

Lotus Notes GetAttachment Fails When Name Has Slashes

Posted on 2007-11-28
10
Medium Priority
?
1,839 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
[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
10 Comments
 

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
Independent Software Vendors: 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 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

771 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