Kevin,
Thanks for your reply.
I had tried searching Google, but to no avail.
The code samples that you found I have tested and do not do anything as far as I can tell.
1st:
vb Code:
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("", "", Missing.Value, Missing.Value) ' TODO:
' Get the first contact from the Contacts folder.
Dim cContacts As Outlook.MAPIFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
Dim oItems As Outlook.Items = cContacts.Items
Dim oCt As Outlook.ContactItem
Try
oCt = oItems.GetFirst()
' Display some common properties.
Console.WriteLine(oCt.FullName)
Console.WriteLine(oCt.Title)
Console.WriteLine(oCt.Birthday)
Console.WriteLine(oCt.CompanyName)
Console.WriteLine(oCt.Department)
Console.WriteLine(oCt.Body)
Console.WriteLine(oCt.FileAs)
Console.WriteLine(oCt.Email1Address)
Console.WriteLine(oCt.BusinessHomePage)
Console.WriteLine(oCt.MailingAddress)
Console.WriteLine(oCt.BusinessAddress)
Console.WriteLine(oCt.OfficeLocation)
Console.WriteLine(oCt.Subject)
Console.WriteLine(oCt.JobTitle)
Catch
Console.WriteLine("an error occurred")
Finally
' Display
'oCt.Display(True)
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oItems = Nothing
oCt = Nothing
End Try
For the logon information when it said "Profile" I wasn't sure if this meant the profile name of the pst by default "Outlook", or my account logon name "firstname" or my full name "firstname surname" or my email address "name@company.com" none seemed to work, so I read that you can use "oNS.Logon("", "", Missing.Value, Missing.Value)" and also that these may not work if outlook is already running..? Well outlook will most likely be running when this program is used, so the code would need to work with outlook already running and also without...
This displayed no information in the console window, but I have definitely got contacts and groups in my Address book.
I tried the 2nd example:
vb Code:
' Create Outlook application.
Dim oApp As Outlook.Application = New Outlook.Application()
' Get Mapi NameSpace and Logon.
Dim oNS As Outlook.NameSpace = oApp.GetNamespace("mapi")
oNS.Logon("", "", Missing.Value, Missing.Value) ' TODO:
' Get Global Address List.
Dim oDLs As Outlook.AddressLists = oNS.AddressLists
Dim oGal As Outlook.AddressList = oDLs.Item("Global Address List")
Console.WriteLine(oGal.Name)
' Get a specific distribution list.
' TODO: Replace the distribution list with a distribution list that is available to you.
Dim sDL As String = "TestDL"
Dim oEntries As Outlook.AddressEntries = oGal.AddressEntries
' No filter available to AddressEntries
Dim oDL As Outlook.AddressEntry = oEntries.Item(sDL)
Console.WriteLine(oDL.Name)
Console.WriteLine(oDL.Address)
Console.WriteLine(oDL.Manager)
' Get all of the members of the distribution list.
oEntries = oDL.Members
Dim oEntry As Outlook.AddressEntry
Dim i As Integer
For i = 1 To oEntries.Count
oEntry = oEntries.Item(i)
Console.WriteLine(oEntry.Name)
' Display the Details dialog box.
'oDL.Details(Missing.Value)
Next
' Log off.
oNS.Logoff()
' Clean up.
oApp = Nothing
oNS = Nothing
oDLs = Nothing
oGal = Nothing
oEntries = Nothing
oEntry = Nothing
In the "for" statement I get an error at "oEntry = oEntries.Item(i)" stating:
NullReferenceException was unhandled
Object reference not set to an instance of an object.
I don't know what is wrong, my Global Address List is full of contacts, have even set up a new TestDL group to practice with, and it doesn't seem to retrieve any contacts...
Any help would be greatly appreciated on this, really want to get this solved.
Thanks again.