Solved

Lotus Notes GetAttachment Fails When Name Has Slashes

Posted on 2007-11-28
10
1,794 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
Comment Utility
0
 

Author Comment

by:AlphaGuys
Comment Utility
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
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
Comment Utility
Don't believe you can use the Evaluate function from VB
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks qwaletee
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now