here is my code for getting all the contacts in outlook. My current contact count is 28533. As for now Im using cache to store all the contacts but my boss requires me not to use cache.
Code:Dim oApp As New Outlook.Application Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi") Dim dt As New DataTable dt.Columns.Add("id", 0.GetType) dt.Columns.Add("name", String.Empty.GetType) dt.Columns.Add("alias", String.Empty.GetType) dt.Columns.Add("firstname", String.Empty.GetType) dt.Columns.Add("lastname", String.Empty.GetType) dt.Columns.Add("contact_no", String.Empty.GetType) dt.Columns.Add("department", String.Empty.GetType) dt.Columns.Add("email", String.Empty.GetType) dt.PrimaryKey = New DataColumn() {dt.Columns("id")} 'oNS.Logon(sUserName, sPassword, False, True) Dim als As Outlook.AddressLists = oNS.AddressLists Dim aes As Outlook.AddressEntries = als("Global Address List").AddressEntries() Dim iAECount As Integer = aes.Count For i As Integer = 1 To iAECount Dim ae As Outlook.AddressEntry = aes.Item(i) If ae IsNot Nothing Then Dim eu As Outlook.ExchangeUser = ae.GetExchangeUser If eu IsNot Nothing Then dt.Rows.Add(New Object() {i, ae.Name, eu.Alias, eu.FirstName, eu.LastName, eu.MobileTelephoneNumber, _ eu.Department, eu.PrimarySmtpAddress}) End If End If Next





Reply With Quote