473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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
1 2062
zhyl
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

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

Similar topics

6
by: Dave Hopper | last post by:
Hi I am using the following SQL to retrieve a value in a list box using a unique ID held in the list box call cntID. The list box is used on an order form to list appointments that have been...
20
by: wolftor | last post by:
Would anyone be willing to beta test my application for me and give me some feedback? I can give you feedback in exchange (ie. if there are parts you're interested in knowing how it was done) or I...
4
by: RM | last post by:
Had VS .Net 2002 installed on W2k Server SP3 and supported a number of web sites. Installed VS .Net 2003 on Friday and now all web sites using .Net & MS ACCESS get this strange error upon open. ...
0
by: toduro | last post by:
Using Visual C# 2005 Express Edition and Microsoft Office Outlook 2003. An exception with message: "Retrieving the COM class factory for component with CLSID...
4
by: kannan | last post by:
Hi, I am new to C# and It may be a simple question. I am trying to loop through MS-Outlook object Contact address list. I can able to find the count using following line. int iAddresscount =...
1
by: kannan | last post by:
Hi, I am trying to loop through outlook contact address and display in messagebox. I have used following code: Outlook._Application olApp = new Outlook.ApplicationClass(); Outlook._NameSpace...
0
by: Klaki | last post by:
I'm trying to create an instance of Outlook using VB.net and every time I run the site, I get the following error: Retrieving the COM class factory for component with CLSID...
1
by: =?Utf-8?B?bWljcm9zbHVn?= | last post by:
Error: Mail could not be sent using the account "Tim Burke" Explanation: relaying denied Error: 5553 Sometimes the error comes up, and sometimes it doesn't and I can send emails. I've...
2
by: RodneyAnonymous | last post by:
I've got some code for composing an e-mail from the contents of an RTF box. The first time I execute it, everything works fine. If I close my app and then re-run it, however, I always receive the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.