Solved

Visual Basic, extract Lotus Notes email attachments

Posted on 2009-05-12
5
1,206 Views
Last Modified: 2013-12-18
Hi There,

I have found that since moving to late binding the attached VB code no longer extracts the filename of attachments in a Lotus Notes client email.  Please note that this is a client tool (not a domino server tool)

Even though the attachments are processed correctly, I have found the following line  produces an empty string.
sFileName = domNotesItem.Values(0)

What do I need to do to be able to continue to use late binidng but extract my files correctly.

Thanks in advance.
Set Doc = nv.GetFirstDocument

    

    Do While (Not (Doc Is Nothing))

        iCount = iCount + 1

        If Len(Doc.NoteID) & Doc.NoteID = sMessageId Then

            'Found!

            sSubject = Doc.GetItemValue("subject")(0)

            sText = Doc.GetItemValue("Body")(0)

            sAttachedFileNames = ""

 

            'Extract all items.

            For Each domattachment In Doc.Items

                Set domNotesItem = domattachment

                If domNotesItem.Type = 1084 Then

                    'OK!!!!! We have the file, lets extract it and create our string

                    sFileName = domNotesItem.Values(0)

                    sAttachmentFiles = sAttachmentFiles & sFileName & "|"

 

                    Call Doc.GetAttachment(sFileName).ExtractFile(sTempFilename)

                    sAttachmentPaths = sAttachmentPaths & sTempFilename & "|"

                End If

            Next

 

            sMessageId = Len(Doc.NoteID) & Doc.NoteID

            ReadMessage = "SUCCESS"

            

            GoTo EXITFUNCTION

        End If

 

        Set Doc = nv.GetNextDocument(Doc)

    Loop

Open in new window

0
Comment
Question by:jcwiatr
  • 4
5 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24419920
I have to guess a bit here, because I don't know the intricacies of using Lotus Notes, but it might be that either:

1) the default accessor (method/property) is not called, you can try it with .Item(index) (but that's only true if it is not an array but a collection of some sort)
2) the Values collection contains empty data, you check in debug env. using Immediate Window
3) or your method is wrong, but I can't tell. Check this: http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/Lotus_SmartSuite/Lotus_Notes/Q_20809433.html#9834399, it may reveal some info I don't have.

otherwise, there are some excellent people around at Lotus Notes, who may be able to help further.
0
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24420020
Ok, my mistake, I should RTFM before posting. From the documentation of Lotus Notes it gives (quote):

For text, number, date-time items, and attachments this property always returns an array, even when there is only a single value in the item. If you know the item contains only a single value, access the first element in the array, which is at index 0. If you know the item contains multiple values, but you don't know how many, iterate over the array using the Forall statement. For attachments, the attachment name can be passed to the GetAttachment method in NotesDocument. This property returns the same value(s) for an item as the GetItemValue method in NotesDocument.
you may want to try the GetItemValue method, perhaps it returns more?

And from that previous link at EE that I posted, I understand that you should be able to do the following, which might work as an alternative method, quote:

Use notesDocument.getFirsttem("$File"), which is the object reference data.  The returned notesItem has property notesIte.text, which will be the file name.  There can be multiple $File items, so delete each one after you process its correspodning getAttachment, by using notesItem.remove.  As long as you don't notesDocument.save, it will have no lasting effect, but will allow you to try to get .getFirstItem("$File") again (returning the next $File instead of the same one again)

-- Abel --
0
 
LVL 39

Expert Comment

by:abel
ID: 24420028
Yet another alternative, which is originates from that same thread, is this: using NotesSession.Evaluate and @AttachmentNames on the NotesDocument
0
 
LVL 1

Author Closing Comment

by:jcwiatr
ID: 31580832
Thanks for your help.  I used the s.Evaluate("@AttachmentNames",Doc) option.
0
 
LVL 39

Expert Comment

by:abel
ID: 24534958
thanks for the follow-up & pts, glad it works.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
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 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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now