Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List
Accessing the Outlook Contact List Accessing the Outlook Contact List
Accessing the Outlook Contact List
Go Back  Xtreme Visual Basic Talk > > > > Accessing the Outlook Contact List


Reply
 
Thread Tools Display Modes
  #1  
Old 04-11-2004, 03:16 PM
reboot's Avatar
rebootAccessing the Outlook Contact List reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,614
Default Accessing the Outlook Contact List


Not extremely well commented, but I think the code is pretty simple and self-explanatory. Also not intended to be any kind of complete app, but just a "here's how it's done" sample. In real life, you'd probably want Properties for all the individual Contact items, instead of returning a big string with all of them in it like I did here. There are also other methods I didn't make use of for this sample. Find and FindNext, for example, would probably be pretty useful to include in the class. I always like to leave something for the reader to play with.

To use this, you'll need to include the Outlook COM Library Reference (when will MS ever bring Office into the .Net fold?? ).

AND.... No "reboot doing VBA??" cracks either!

Sample usage would be something like

Code:
outlookContacts = New GetOutlookContacts Textbox1.Text = outlookContacts.GetFirstContact() outlookContacts = Nothing
and the Class

Code:
Imports System Imports System.Text Imports System.Environment 'walks the outlook contact list Public Class GetOutlookContacts Private _olApplication As Outlook.Application Private _olNameSpace As Outlook.NameSpace Private _olContacts As Outlook.MAPIFolder Private _olItems As Outlook.Items Private _olContactItem As Outlook.ContactItem 'constructor Public Sub New() 'create Outlook application. _olApplication = New Outlook.Application 'get nameSpace and logon. _olNameSpace = _olApplication.GetNamespace("mapi") _olNameSpace.Logon("Outlook", "", False, True) 'get the contact items _olContacts = _olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts) _olItems = _olContacts.Items End Sub Public Function GetFirstContact() As String 'get the first contact from the Contacts folder. Try _olContactItem = CType(_olItems.GetFirst(), Outlook.ContactItem) Return BuildContactString() Catch Return "An error occurred" End Try End Function Public Function GetPreviousContact() As String 'get the previous contact from the Contacts folder. Try _olContactItem = CType(_olItems.GetPrevious(), Outlook.ContactItem) Return BuildContactString() Catch Return "An error occurred" End Try End Function Public Function GetNextContact() As String 'get the next contact from the Contacts folder. Try _olContactItem = CType(_olItems.GetNext(), Outlook.ContactItem) Return BuildContactString() Catch Return "An error occurred" End Try End Function Public Function GetLastContact() As String ' Get the last contact from the Contacts folder. Try _olContactItem = CType(_olItems.GetLast(), Outlook.ContactItem) Return BuildContactString() Catch Return "An error occurred" End Try End Function Private Function BuildContactString() As String Dim sb As New StringBuilder 'return some common properties. sb.Append(_olContactItem.FullName) sb.Append(NewLine) sb.Append(_olContactItem.Title) sb.Append(NewLine) sb.Append(_olContactItem.Birthday) sb.Append(NewLine) sb.Append(_olContactItem.CompanyName) sb.Append(NewLine) sb.Append(_olContactItem.Department) sb.Append(NewLine) sb.Append(_olContactItem.Body) sb.Append(NewLine) sb.Append(_olContactItem.FileAs) sb.Append(NewLine) sb.Append(_olContactItem.Email1Address) sb.Append(NewLine) sb.Append(_olContactItem.BusinessHomePage) sb.Append(NewLine) sb.Append(_olContactItem.MailingAddress) sb.Append(NewLine) sb.Append(_olContactItem.BusinessAddress) sb.Append(NewLine) sb.Append(_olContactItem.OfficeLocation) sb.Append(NewLine) sb.Append(_olContactItem.Subject) sb.Append(NewLine) sb.Append(_olContactItem.JobTitle) Return sb.ToString End Function 'destructor Protected Overrides Sub Finalize() 'log off. _olNameSpace.Logoff() 'clean up. _olApplication = Nothing _olNameSpace = Nothing _olItems = Nothing _olContactItem = Nothing End Sub End Class

Last edited by reboot; 04-12-2004 at 07:53 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
dispalying the Global Address list from OUTLOOK on a VB Program Small Mind Communications 1 12-18-2002 01:49 AM
Using Outlook Contact in Web Page gbitguy General 1 11-05-2002 01:41 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List Accessing the Outlook Contact List
Accessing the Outlook Contact List
Accessing the Outlook Contact List
 
Accessing the Outlook Contact List
Accessing the Outlook Contact List
 
-->