473,881 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

8 New Member
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;
}
}
}
Apr 2 '08 #1
1 2120
zhyl
3 New Member
Hi,

Why not try Advanced Outlook Express Repair at http://www.datanumen.c om/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
9659
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 made for service staff. My problem is the SQL is not retrieving the value of the listbox. I have tested the SQL by entering a fixed value of a valid entry in the listbox and it works fine, but as soon as I replace the fixed value with...
20
2956
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 can give you a free license if you want to use it. It should install OK but that is part of the problem that needs to be verified on all platforms so that people can just download it in the future, install and use it. It has an mde front...
4
2546
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. ASP=/TestDotNet/AdoNet.aspx System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at System.Data.OleDb.OleDbConnection.InitializeProvider() at System.Data.OleDb.OleDbConnection.Open()...
0
4778
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 {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 8007007e" is thrown during processing of the statement: "Microsoft.Office.Interop.Outlook.Application outlook_app = new
4
2780
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 = ((Outlook.Application)application).GetNamespace("MAPI").AddressLists.Count; but I want to loop through each contacts and display in the messagebox. How
1
2173
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 olNs = olApp.GetNamespace("MAPI"); Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); Outlook.Items oItems = oContacts.Items;
0
3089
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 {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80010001. If I run debug on my PC using Visual Sturdio 2005, it works, but when I publish it to the web server, I get the error. I have Office installed on the web server with the Interop...
1
1680
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 contacted my my service providers and confirmed that all the information is correct. I've tried using various cities as a option and that does not work. I can recieve emails fine. Somedays I can send and some days I
2
10743
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 following error: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80040154. When reaching the line: Outlook.Application outlookApp = new...
0
9926
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11096
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10812
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9552
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7108
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4597
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3223
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.