Solved

VB.Net loop though Outlook folder Need to find type of item....

Posted on 2003-12-10
1
1,550 Views
Last Modified: 2012-05-04
I have a loop that loops though each message in a Outlook folder...  Outlook 2003/ VB.Net 2003/ XP operating system.
Exchange 5.5

        Dim myOlapp As Outlook.Application
        Dim myoMsg As Outlook.MailItem
        Dim myOFolder As Outlook.MAPIFolder

        myOlapp = CreateObject("Outlook.Application")
        myoMsg = myOlapp.CreateItem(Outlook.OlItemType.olMailItem)
        myOFolder = GetFolder(sInboxMailFolder)
        for each myomsg   in myOfolder.items
            If myoMsg.Attachments.Count > 0 Then
             ....
             ......
           end if
        next message.

My probem is that sometimes there are other types of messages in there (Hidden, contacts etc).

I would like to see the type first then do something with it.

What is the best way to do this.

Thanks,

Rog
0
Comment
Question by:Rog
[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
1 Comment
 
LVL 4

Accepted Solution

by:
bhartung earned 250 total points
ID: 9921077
You could use the MessageClass property of the Item to tell what kind it is.  Perhaps you want to just deal with mail items.  One way to restrict the list of items to those of a particular class is with the Restrict method on the Items collection.  There's probably a better way to do this, but:

Dim myOlapp As New Outlook.Application
Dim myOFolder As Outlook.MAPIFolder
Dim myoNS As Outlook.NameSpace
Dim myoItems As Outlook.Items
Dim myoMsg As Outlook.MailItem

Set myoNS = myOlapp.GetNamespace("MAPI")
Set myOFolder = myoNS.GetDefaultFolder(olFolderInbox)
       
Set myoItems = myOFolder.Items.Restrict("[Message Class]='IPM.Note'")
       
For Each myoMsg In myoItems
    If myoMsg.Attachments.Count > 0 Then
        MsgBox myoMsg.Subject & " has " & myoMsg.Attachments.Count & " attachments"
    End If
Next
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Six Sigma Control Plans

724 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