Click here to Skip to main content
11,925,292 members (60,561 online)
Click here to Skip to main content
Add your own
alternative version


160 bookmarked

.NET Connector for Microsoft Outlook

, 19 Feb 2004
Rate this:
Please Sign up or sign in to vote.
Export Microsoft Outlook data using XML DataSets and the Outlook COM Object Library.


The Microsoft Outlook Connector is written in C# using the .NET 1.1 Framework. It attempts to abstract the data access with Microsoft Outlook and visual components using the data. Data from your Microsoft Outlook application can be exported to an XML file by simply checking the folder options and clicking Export. The source provides a simple example of mapping the COM object properties to a XML-friendly DataSet that could be used in any .NET application.


This component for exporting Outlook objects stemmed from a couple years passively looking for a sync between my database and Outlook. I somehow stumbled on a VBA article on it ( and decided to make a C# app to do the same.

Using the code

The primary function of the DataExportForm retrieves information from the user's Microsoft Outlook application via a custom connector which translates the Interop COM objects into basic DataSets. We should all be aware of how handy DataSets can be so lets look at how our form gets the information for the datagrid.

private DataSet getCheckedItemSet()
    DataSet ds = new DataSet();
    OutlookConnector outlook = new OutlookConnector();

    // setup progress bars and process selected folders
    pgFolderProgress.Value = 0;
    outlook.ItemProcessed += new OutlookItemProcessed(outlook_ItemProcessed);
    pgFolderProgress.Maximum = lstExportObjects.CheckedItems.Count;
    foreach (ListViewItem obj in lstExportObjects.CheckedItems)
        pgItemProgress.Value = 0;

        switch (obj.Index) 
            case 0:
                pgItemProgress.Maximum = outlook.getFolderCount(
            case 1:
                pgItemProgress.Maximum = outlook.getFolderCount(
            case 2:
                pgItemProgress.Maximum = outlook.getFolderCount(
            case 3:
                pgItemProgress.Maximum = outlook.getFolderCount(
            case 4:
                pgItemProgress.Maximum = outlook.getFolderCount(
                Debug.WriteLine("Unsupported Export: " + obj.Index);
    return ds;

Now how exactly does the OutlookConnector get it? You'll have to download the source to see the finer details of handling the Interop connection. Rest assured that it implements the IDisposable interface and works through MAPI to retrieve Outlook folder information. All of the Outlook connectivity is handled on instantiation which makes retrieval pretty easy, as seen here in the OutlookConnector.getContactDataSet() method.

/// <summary>
/// Retrieves a list of all the Outlook Contacts.
/// </summary>
/// <returns>Contact Items DataSet</returns>
public DataSet getContactDataSet()
    Outlook.ContactItem item;
    DataSet rv = new DataSet();
    rv.DataSetName = "Contacts";

        objFolder = objNamespace.GetDefaultFolder(
        Debug.WriteLine(objFolder.Items.Count + " Contacts found.");
        foreach (System.Object _item in objFolder.Items) 
            item = (Outlook.ContactItem) _item;
            rv.Tables[0].Rows.Add(new object[] {
        Debug.WriteLine(rv.Tables[0].Rows.Count + " Contacts exported.");
    catch (System.Exception e)
    return rv;

Points of Interest

If your system does not have Microsoft Office Outlook 2003 you may have to change the References used by the "OutlookConnector" project. That is to say, if you received a build error described as "The type of namespace name 'Outlook' could not be found", you probably don't have Office 2003. Simply expand the project references, remove the afflicted items, and add the COM Library appropriate for your system. If someone has a dynamic way to handle this, I'd be curious to see you've done.


I wanted to limit this project to a single evening so it currently uses untyped DataSets. The real advantage of this application would come from using strong types and hooking in some DataAdapter(s) to really try to sync with some other system. I will probably end up tying in a MySQL data adapter in the coming weeks as time permits but if someone starts/finishes before I get to it, please let me know.

Version 1.1

Connector looping was switched to an incrementing localized integer since Office 10 does not implement a GetEnumerator() method. We have to use our own counter in a for loop instead. Also, here are some details on fixing your References between Office versions.

<!----------------------------- Article Ends ----------------------------->


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Mathias Taylor
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHow to read large number of items from a folder? Pin
BlackMilan7-Apr-14 2:20
memberBlackMilan7-Apr-14 2:20 
BugSource code for get Inbox mail from outlook To web page Pin
Manish Pandey19-Apr-13 1:29
memberManish Pandey19-Apr-13 1:29 missing? Pin
Syed haseeb baber27-Feb-12 2:49
memberSyed haseeb baber27-Feb-12 2:49 
AnswerRe: missing? Pin
Syed haseeb baber27-Feb-12 3:22
memberSyed haseeb baber27-Feb-12 3:22 
Generalhu Pin
Member 779129431-Mar-11 6:43
memberMember 779129431-Mar-11 6:43 
GeneralSolution for the same item in every row Pin
Tom Klein17-Jan-11 1:31
memberTom Klein17-Jan-11 1:31 
GeneralRe: Solution for the same item in every row Pin
Bakk Andris14-Mar-11 8:00
memberBakk Andris14-Mar-11 8:00 
GeneralI tried to execute this code, it is giving an error "does not contain a definition for 'SenderEmailAddress'" Pin
Member 397979324-Jun-09 20:29
memberMember 397979324-Jun-09 20:29 
QuestionMicrosoft.Outlook11 missing Pin
disire8-Dec-08 23:21
memberdisire8-Dec-08 23:21 
AnswerRe: Microsoft.Outlook11 missing Pin
tforsberg25-Feb-15 9:33
professionaltforsberg25-Feb-15 9:33 
QuestionHow can we do this in Asp.Net Pin
SKP2425-Mar-08 5:13
memberSKP2425-Mar-08 5:13 
Generalconvert "X.400/X.500 e-mail adress" into "Smtp e-mail adress" Pin
jackyontherock10-Aug-07 6:11
memberjackyontherock10-Aug-07 6:11 
GeneralExtracting/Importing [modified] Pin
ClaudeX6-Jun-07 23:57
memberClaudeX6-Jun-07 23:57 
Any idea how to extract those free timing from microsoft outlook calendar (those timing that is without appointment) using visual basic or C#?

Btw...can it be done without using Microsoft Exchange Server?

Please Help...
Thanks in advance

Best Regards,

-- modified at 5:31 Thursday 7th June, 2007
GeneralOutlook Namespace missing Pin
MarkChimes22-Feb-07 14:17
memberMarkChimes22-Feb-07 14:17 
GeneralRe: Outlook Namespace missing Pin
MarkChimes22-Feb-07 14:53
memberMarkChimes22-Feb-07 14:53 
GeneralExisting Outlook window closes ! Pin
ccangaroo24-Aug-06 4:29
memberccangaroo24-Aug-06 4:29 
GeneralA bug Pin
nadav741-Jul-06 10:38
membernadav741-Jul-06 10:38 
GeneralRe: A bug [modified] Pin
robocato31-Aug-06 2:19
memberrobocato31-Aug-06 2:19 
GeneralPlease Help Pin
Ashisvadada14-Jun-06 18:36
memberAshisvadada14-Jun-06 18:36 
QuestionProblem ??? Pin
Pascal Groulx16-May-06 13:06
memberPascal Groulx16-May-06 13:06 
GeneralgoUsing this code with Exchange Pin
DeborahK28-Mar-06 10:18
memberDeborahK28-Mar-06 10:18 
GeneralDrag & Drop outlook contacts Pin
NewbieDude16-Mar-06 21:22
memberNewbieDude16-Mar-06 21:22 
GeneralProblem Pin
pro_8618-Feb-06 12:59
memberpro_8618-Feb-06 12:59 
QuestionHow about processing any PST? Pin
Matt Philmon14-Feb-06 7:35
memberMatt Philmon14-Feb-06 7:35 
GeneralBUG inside OutlookItemBuilder class and resolution. Pin
Preky6-Jul-05 22:51
memberPreky6-Jul-05 22:51 
GeneralAlways return 1 item Pin
sksandz8-Apr-05 2:08
membersksandz8-Apr-05 2:08 
GeneralRe: Always return 1 item Pin
CtrAltDel30-Apr-05 11:22
memberCtrAltDel30-Apr-05 11:22 
GeneralRe: Always return 1 item Pin 23:09 23:09 
GeneralRe: Always return 1 item Pin
Member 33064021-Jan-08 7:58
memberMember 33064021-Jan-08 7:58 
GeneralNullReferenceException when running the code Pin
pvsunil8-Apr-05 1:32
memberpvsunil8-Apr-05 1:32 
Generalexporting e-mails of additional mailbox Pin
MagicGirL8330-Mar-05 17:24
sussMagicGirL8330-Mar-05 17:24 
Generaldisplay the exported e-mails on a web page Pin
MagicGirL8330-Mar-05 14:38
sussMagicGirL8330-Mar-05 14:38 
GeneralMS Outlook FAXMaker Pin
Fayeeg2-Feb-05 0:41
memberFayeeg2-Feb-05 0:41 
Questionhow can i disbled prompt:A program is trying to access e-mail addresses you have stored in outlook Pin
nazli17-Jan-05 5:18
membernazli17-Jan-05 5:18 
AnswerRe: how can i disbled prompt:A program is trying to access e-mail addresses you have stored in outlook Pin
Mathias Taylor8-Feb-05 18:32
memberMathias Taylor8-Feb-05 18:32 
Generalexport error Pin
telynor24-Nov-04 23:53
membertelynor24-Nov-04 23:53 
GeneralUpdated/Current Source Available at SourceForge Pin
Mathias Taylor15-Nov-04 20:33
sussMathias Taylor15-Nov-04 20:33 
GeneralRe: Updated/Current Source Available at SourceForge Pin
dude_401222-Dec-04 13:52
memberdude_401222-Dec-04 13:52 
GeneralRe: Updated/Current Source Available at SourceForge Pin
Mathias Taylor6-Feb-05 3:29
memberMathias Taylor6-Feb-05 3:29 
GeneralCustomizing the Outlook 2003 New Message Form Pin
Ganesh Agrawal15-Oct-04 11:57
memberGanesh Agrawal15-Oct-04 11:57 
GeneralgetAttachments Pin
nazli3-Oct-04 22:42
membernazli3-Oct-04 22:42 
GeneralRe: getAttachments Pin
Prakash Kalakoti7-Jun-05 2:27
memberPrakash Kalakoti7-Jun-05 2:27 
GeneralRe: getAttachments Pin
bhavna81624-Jan-07 0:08
memberbhavna81624-Jan-07 0:08 
GeneralMailItem.SenderEmailAddress does not exist! Pin
miagao13-Sep-04 4:41
membermiagao13-Sep-04 4:41 
GeneralOutlook2000 problem with GetEnumerator Pin
miagao7-Sep-04 6:23
membermiagao7-Sep-04 6:23 
GeneralRe: Outlook2000 problem with GetEnumerator Pin
Nicholas Cardi7-Sep-04 6:48
memberNicholas Cardi7-Sep-04 6:48 
GeneralRe: Outlook2000 problem with GetEnumerator Pin
miagao13-Sep-04 4:37
membermiagao13-Sep-04 4:37 
GeneralRe: Outlook2000 problem with GetEnumerator Pin
telynor25-Nov-04 3:01
membertelynor25-Nov-04 3:01 
GeneralRe: Outlook2000 problem with GetEnumerator Pin
Mathias Taylor26-Nov-04 13:51
sussMathias Taylor26-Nov-04 13:51 
GeneralException Thrown... Pin
John Gray26-Jun-04 15:27
sussJohn Gray26-Jun-04 15:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151126.1 | Last Updated 20 Feb 2004
Article Copyright 2003 by Mathias Taylor
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid