By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Error in retrieving a contact from Microsoft outlook using asp.net with c#

P: 8
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.NullReferenceException' occurred in ConsoleApplication1.exe,Additional 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.Reflection; // to use Missing.Value
//TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
//using Outlook = Microsoft.Office.Interop.Outlook;

namespace ConsoleApplication1
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();

// Get the NameSpace information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);

Console.WriteLine("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("YourValidProfile", Missing.Value, false, true);

// Get the default Contacts folder.
Outlook.MAPIFolder oContacts = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFo lderContacts);

// 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.ContactItem oCt = (Outlook.ContactItem)oItems.GetFirst();

// Output 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);

// Display the contact.
oCt.Display(true);

// Log off.
oNS.Logoff();

// Explicitly release objects.
oCt = null;
oItems = null;
oContacts = null;
oNS = null;
oApp = null;
}

//Simple error handling.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}

//Default return value.
return 0;
}
}
}
Apr 2 '08 #1
Share this Question
Share on Google+
1 Reply


P: 3
Hi,

Why not try Advanced Outlook Express Repair at http://www.datanumen.com/aoer/ ? It recovers several important Outlook Express dbx files for me and is really helpful!

Alan
Apr 4 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.