Hi,
I'm getting an exception while tried to retrive an outlook contact using asp.net in a console application.
The exception is as follows:
An unhandled exception of type 'System.NullRef erenceException ' occurred in ConsoleApplicat ion1.exe,Additi onal information: Object reference not set to an instance of an object
..
Can anybody help me pls....
my code is like this..
using System;
using System.Reflecti on; // to use Missing.Value
//TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
//using Outlook = Microsoft.Offic e.Interop.Outlo ok;
namespace ConsoleApplicat ion1
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Applica tion oApp = new Outlook.Applica tion();
// Get the NameSpace information.
Outlook.NameSpa ce oNS = oApp.GetNamespa ce("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missi ng.Value, Missing.Value, true, true);
Console.WriteLi ne("searching folder");
// Alternate logon method that uses a specific profile.
// TODO: If you use this logon method,
// change the profile name to an appropriate value.
oNS.Logon("Your ValidProfile", Missing.Value, false, true);
// Get the default Contacts folder.
Outlook.MAPIFol der oContacts = oNS.GetDefaultF older(Outlook.O lDefaultFolders .olFolderContac ts);
// Get the Items collection from the folder.
Outlook.Items oItems = (Outlook.Items) oContacts.Items ;
int itemcount = oItems.Count;
// Get the first contact item in the Items collection.
Outlook.Contact Item oCt = (Outlook.Contac tItem)oItems.Ge tFirst();
// Output some common properties.
Console.WriteLi ne(oCt.FullName );
Console.WriteLi ne(oCt.Title);
Console.WriteLi ne(oCt.Birthday );
Console.WriteLi ne(oCt.CompanyN ame);
Console.WriteLi ne(oCt.Departme nt);
Console.WriteLi ne(oCt.Body);
Console.WriteLi ne(oCt.FileAs);
Console.WriteLi ne(oCt.Email1Ad dress);
Console.WriteLi ne(oCt.Business HomePage);
Console.WriteLi ne(oCt.MailingA ddress);
Console.WriteLi ne(oCt.Business Address);
Console.WriteLi ne(oCt.OfficeLo cation);
Console.WriteLi ne(oCt.Subject) ;
Console.WriteLi ne(oCt.JobTitle );
// Display the contact.
oCt.Display(tru e);
// Log off.
oNS.Logoff();
// Explicitly release objects.
oCt = null;
oItems = null;
oContacts = null;
oNS = null;
oApp = null;
}
//Simple error handling.
catch (Exception e)
{
Console.WriteLi ne("{0} Exception caught.", e);
}
//Default return value.
return 0;
}
}
}
I'm getting an exception while tried to retrive an outlook contact using asp.net in a console application.
The exception is as follows:
An unhandled exception of type 'System.NullRef erenceException ' occurred in ConsoleApplicat ion1.exe,Additi onal information: Object reference not set to an instance of an object
..
Can anybody help me pls....
my code is like this..
using System;
using System.Reflecti on; // to use Missing.Value
//TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
//using Outlook = Microsoft.Offic e.Interop.Outlo ok;
namespace ConsoleApplicat ion1
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Applica tion oApp = new Outlook.Applica tion();
// Get the NameSpace information.
Outlook.NameSpa ce oNS = oApp.GetNamespa ce("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missi ng.Value, Missing.Value, true, true);
Console.WriteLi ne("searching folder");
// Alternate logon method that uses a specific profile.
// TODO: If you use this logon method,
// change the profile name to an appropriate value.
oNS.Logon("Your ValidProfile", Missing.Value, false, true);
// Get the default Contacts folder.
Outlook.MAPIFol der oContacts = oNS.GetDefaultF older(Outlook.O lDefaultFolders .olFolderContac ts);
// Get the Items collection from the folder.
Outlook.Items oItems = (Outlook.Items) oContacts.Items ;
int itemcount = oItems.Count;
// Get the first contact item in the Items collection.
Outlook.Contact Item oCt = (Outlook.Contac tItem)oItems.Ge tFirst();
// Output some common properties.
Console.WriteLi ne(oCt.FullName );
Console.WriteLi ne(oCt.Title);
Console.WriteLi ne(oCt.Birthday );
Console.WriteLi ne(oCt.CompanyN ame);
Console.WriteLi ne(oCt.Departme nt);
Console.WriteLi ne(oCt.Body);
Console.WriteLi ne(oCt.FileAs);
Console.WriteLi ne(oCt.Email1Ad dress);
Console.WriteLi ne(oCt.Business HomePage);
Console.WriteLi ne(oCt.MailingA ddress);
Console.WriteLi ne(oCt.Business Address);
Console.WriteLi ne(oCt.OfficeLo cation);
Console.WriteLi ne(oCt.Subject) ;
Console.WriteLi ne(oCt.JobTitle );
// Display the contact.
oCt.Display(tru e);
// Log off.
oNS.Logoff();
// Explicitly release objects.
oCt = null;
oItems = null;
oContacts = null;
oNS = null;
oApp = null;
}
//Simple error handling.
catch (Exception e)
{
Console.WriteLi ne("{0} Exception caught.", e);
}
//Default return value.
return 0;
}
}
}
Comment