EDN Admin
Well-known member
Hi guys,
Im trying to write a code which reads all email addresses in the Outlook Address Book and store it in a List. However i cant get it to print out anything at the Command Prompt due to System.NullReferenceException.
I;m using Outlook 2007 & Visual Studio 2005
My C# Code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using Microsoft.Office.Interop.Outlook;
<span style="color:Blue; namespace ReadContact
{
<span style="color:Blue; public <span style="color:Blue; class Class1
{
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; void Main()
{
<span style="color:Green; // Create the Outlook application.
Application oApp = <span style="color:Blue; new Application();
NameSpace oNS = oApp.Session;
AddressList addList;
Items oItems;
AddressLists addLists;
AddressEntries addEntries;
AddressEntry addEntry;
_ContactItem contact;
addLists = oNS.AddressLists;
addList = addLists[1];
addEntries = addList.AddressEntries;
addEntry = addEntries.GetFirst();
addEntry = addEntries.GetNext();
contact = addEntry.GetContact();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < 10; i++) <span style="color:Green; // print info for first 10 entries
{
Console.WriteLine(addEntry.Name);<span style="color:Green; // able to print Names
String buffer = contact.Email1Address; <span style="color:Green; // System.NullReferenceException occurs here
Console.WriteLine(buffer);
addEntry = addEntries.GetNext();
}
}
}
}
[/code]
Can anyone teach me how to use the GetContact() method? Am I doing it the right way?
Im able to print out the Names of the contact which means that I can access the Address Book, but I cant print the emails.
Ive checked the Address Book and Im sure that the Email Address fields are not empty, but I do not know why the program stated that it is Null.
View the full article
Im trying to write a code which reads all email addresses in the Outlook Address Book and store it in a List. However i cant get it to print out anything at the Command Prompt due to System.NullReferenceException.
I;m using Outlook 2007 & Visual Studio 2005
My C# Code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using Microsoft.Office.Interop.Outlook;
<span style="color:Blue; namespace ReadContact
{
<span style="color:Blue; public <span style="color:Blue; class Class1
{
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; void Main()
{
<span style="color:Green; // Create the Outlook application.
Application oApp = <span style="color:Blue; new Application();
NameSpace oNS = oApp.Session;
AddressList addList;
Items oItems;
AddressLists addLists;
AddressEntries addEntries;
AddressEntry addEntry;
_ContactItem contact;
addLists = oNS.AddressLists;
addList = addLists[1];
addEntries = addList.AddressEntries;
addEntry = addEntries.GetFirst();
addEntry = addEntries.GetNext();
contact = addEntry.GetContact();
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < 10; i++) <span style="color:Green; // print info for first 10 entries
{
Console.WriteLine(addEntry.Name);<span style="color:Green; // able to print Names
String buffer = contact.Email1Address; <span style="color:Green; // System.NullReferenceException occurs here
Console.WriteLine(buffer);
addEntry = addEntries.GetNext();
}
}
}
}
[/code]
Can anyone teach me how to use the GetContact() method? Am I doing it the right way?
Im able to print out the Names of the contact which means that I can access the Address Book, but I cant print the emails.
Ive checked the Address Book and Im sure that the Email Address fields are not empty, but I do not know why the program stated that it is Null.
View the full article