locked
Read Outlook calender details... RRS feed

  • Question

  • Hi All,

    I want to read all the Outlook calender details including meetings, appoinments, tasks etc.  I want to get all the outlook details and populate them in the datagridview.

    How we can do this using C# and .Net framework 4.0.

     

    Thanks in advance,

    IamHuM

     

    Tuesday, November 22, 2011 4:40 PM

Answers

  • Hi IamHuM,

    Welcome to MSDN Forum.

    To read data (such as mails, contacts, calendars, meetings, appointments, tasks etc.) from Outlook by using C# or VB.Net, we need to call the COM component “Microsoft Outlook Object Library” as the below instruction in this KB article:

    How to use the Microsoft Outlook Object Library to retrieve an appointment by using Visual C#

    http://support.microsoft.com/kb/310259

    using System;
    using System.Reflection;
    using Outlook = Microsoft.Office.Interop.Outlook;
     
    namespace RetrieveAppointment
    {
       public class Class1
       {
          public static int Main(string[] args)
          {
             try 
             {
                // Create the Outlook application.
                Outlook.Application oApp = new Outlook.Application();
     
                // Get the NameSpace and Logon information.
                // Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
                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); 
     
                //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 Calendar folder.
                Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
     
                // Get the Items (Appointments) collection from the Calendar folder.
                Outlook.Items oItems = oCalendar.Items;
                
                // Get the first item.
                Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem) oItems.GetFirst();
     
     
                // Show some common properties.
                Console.WriteLine("Subject: " + oAppt.Subject);
                Console.WriteLine("Organizer: " + oAppt.Organizer);
                Console.WriteLine("Start: " + oAppt.Start.ToString());
                Console.WriteLine("End: " + oAppt.End.ToString());
                Console.WriteLine("Location: " + oAppt.Location);
                Console.WriteLine("Recurring: " + oAppt.IsRecurring);
       
                //Show the item to pause.
                oAppt.Display(true);
     
                // Done. Log off.
                oNS.Logoff();
     
                // Clean up.
                oAppt = null;
                oItems = null;
                oCalendar = null;
                oNS = null;
                oApp = null;
             }
     
                //Simple error handling.
             catch (Exception e)
             {
                Console.WriteLine("{0} Exception caught.", e);
             }  
     
             //Default return value
             return 0;
      
          }
       }
    }

     

    To bind the Outlook information list to DataGridViewn, we have to iterate these item list and add them manually into DataGridView, or create an object that holds the data such as an ArrayList, then binding to DataGridView.

    Like this code sample: Accessing Outlook contacts list in C# and show on DataGridView

    http://www.c-sharpcorner.com/uploadfile/hirendra_singh/accessing-outlook-contacts-list-in-C-Sharp/

    Another code samples for your reference:

    Hot to read outlook calendar from .net

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/83af3946-6ab7-465b-bc06-7c89d8fa1143/

    Get all Outlook calendar items by using C#

    http://stackoverflow.com/questions/90899

     

    By the way, there is the dedicated Outlook Developers Forum.

    http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads



    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Martin_Xie Tuesday, December 6, 2011 8:30 AM
    • Marked as answer by Martin_Xie Tuesday, December 6, 2011 8:31 AM
    Friday, November 25, 2011 8:19 AM

All replies

  • Hi All,

              Can anybody help me with suggestion/links/documens for this request.

              Thanks in advance,

    IamHuM

    Wednesday, November 23, 2011 4:57 AM
  • Outlook doesn't store these types of details, it's just a program to read them from some other source.  You would need to know what that source is and access it directly, bypassing Outlook.
    Wednesday, November 23, 2011 7:35 PM
  • Hi IamHuM,

    Welcome to MSDN Forum.

    To read data (such as mails, contacts, calendars, meetings, appointments, tasks etc.) from Outlook by using C# or VB.Net, we need to call the COM component “Microsoft Outlook Object Library” as the below instruction in this KB article:

    How to use the Microsoft Outlook Object Library to retrieve an appointment by using Visual C#

    http://support.microsoft.com/kb/310259

    using System;
    using System.Reflection;
    using Outlook = Microsoft.Office.Interop.Outlook;
     
    namespace RetrieveAppointment
    {
       public class Class1
       {
          public static int Main(string[] args)
          {
             try 
             {
                // Create the Outlook application.
                Outlook.Application oApp = new Outlook.Application();
     
                // Get the NameSpace and Logon information.
                // Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
                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); 
     
                //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 Calendar folder.
                Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
     
                // Get the Items (Appointments) collection from the Calendar folder.
                Outlook.Items oItems = oCalendar.Items;
                
                // Get the first item.
                Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem) oItems.GetFirst();
     
     
                // Show some common properties.
                Console.WriteLine("Subject: " + oAppt.Subject);
                Console.WriteLine("Organizer: " + oAppt.Organizer);
                Console.WriteLine("Start: " + oAppt.Start.ToString());
                Console.WriteLine("End: " + oAppt.End.ToString());
                Console.WriteLine("Location: " + oAppt.Location);
                Console.WriteLine("Recurring: " + oAppt.IsRecurring);
       
                //Show the item to pause.
                oAppt.Display(true);
     
                // Done. Log off.
                oNS.Logoff();
     
                // Clean up.
                oAppt = null;
                oItems = null;
                oCalendar = null;
                oNS = null;
                oApp = null;
             }
     
                //Simple error handling.
             catch (Exception e)
             {
                Console.WriteLine("{0} Exception caught.", e);
             }  
     
             //Default return value
             return 0;
      
          }
       }
    }

     

    To bind the Outlook information list to DataGridViewn, we have to iterate these item list and add them manually into DataGridView, or create an object that holds the data such as an ArrayList, then binding to DataGridView.

    Like this code sample: Accessing Outlook contacts list in C# and show on DataGridView

    http://www.c-sharpcorner.com/uploadfile/hirendra_singh/accessing-outlook-contacts-list-in-C-Sharp/

    Another code samples for your reference:

    Hot to read outlook calendar from .net

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/83af3946-6ab7-465b-bc06-7c89d8fa1143/

    Get all Outlook calendar items by using C#

    http://stackoverflow.com/questions/90899

     

    By the way, there is the dedicated Outlook Developers Forum.

    http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads



    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Martin_Xie Tuesday, December 6, 2011 8:30 AM
    • Marked as answer by Martin_Xie Tuesday, December 6, 2011 8:31 AM
    Friday, November 25, 2011 8:19 AM
  • And there is another good idea in this article. It created the OutLookInterface class where Outlook data is converted into DataTable objects and then binding into a DataGridView.

    http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_23150735.html

    <Check the link about the OutLookInterface class details>

    OutLookInterface FObject;
     
     private void btnMail_Click(object sender, EventArgs e)
            {
                FObject.populateInbox();
                grdVwData.DataSource = FObject.Mails;
            }
     
            private void btnContacts_Click(object sender, EventArgs e)
            {
                FObject.PopulateContact();
                grdVwData.DataSource = FObject.Contact;
            }
     
            private void btnAppointments_Click(object sender, EventArgs e)
            {
                FObject.PopulateAppointments();
                grdVwData.DataSource = FObject.Appointment;
            }
     
            private void btnNotes_Click(object sender, EventArgs e)
            {
                FObject.PopulateNotes();
                grdVwData.DataSource = FObject.Notes;
            }
     
            private void btnTasks_Click(object sender, EventArgs e)
            {
                FObject.PopulateTasks();
                grdVwData.DataSource = FObject.Tasks;
            }
     

    Martin Xie [MSFT]
    MSDN Community Support | Feedback to us
    Friday, November 25, 2011 8:29 AM
  • I would try to see if webdav is available.

    Webdav is the preferred way to read emails from an outlook server, and I would be surprised if you couldn't probe calendars using Webdav.

    I have only tried to read mail using it though.

    Friday, November 25, 2011 9:15 AM