RobDog888
Jun 25th, 2008, 02:36 PM
Just a quick example on retrieving the number of items in a given folder in a given account.
The count is the number of items in the folder and any subfolders recursively.
VB.NET 2002-2008 and Outlook 2000-2007
Option Explicit On
Option Strict On
'Add a COM reference to Outlook xx.0 Object Library
Imports Microsoft.Office.Interop
'Add a Button1 and TextBox1 to your form.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim oApp As Outlook.Application
'Create an application instance
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
'Logon to your desired session providing the profile name and password
oApp.Session.Logon("YouProfileNameGoesHere", Me.TextBox1.Text, False, False)
'Display the count for the Inbox
MessageBox.Show("Item Count: " & oApp.GetNamespace("MAPI").GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderInbox).Items.Count.ToString, _
"Count", MessageBoxButtons.OK)
'Optionally logoff and close outlook
'oApp.Session.Logoff()
'oApp.Quit()
'oApp = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK)
End Try
End Sub
End Class
The count is the number of items in the folder and any subfolders recursively.
VB.NET 2002-2008 and Outlook 2000-2007
Option Explicit On
Option Strict On
'Add a COM reference to Outlook xx.0 Object Library
Imports Microsoft.Office.Interop
'Add a Button1 and TextBox1 to your form.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim oApp As Outlook.Application
'Create an application instance
oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
'Logon to your desired session providing the profile name and password
oApp.Session.Logon("YouProfileNameGoesHere", Me.TextBox1.Text, False, False)
'Display the count for the Inbox
MessageBox.Show("Item Count: " & oApp.GetNamespace("MAPI").GetDefaultFolder( _
Outlook.OlDefaultFolders.olFolderInbox).Items.Count.ToString, _
"Count", MessageBoxButtons.OK)
'Optionally logoff and close outlook
'oApp.Session.Logoff()
'oApp.Quit()
'oApp = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK)
End Try
End Sub
End Class