Outlook with .NET 2.0

0 comments

Outlook Object Model Overview

For accessing the outlook and its features you have to add reference of Microsoft Outlook 11.0 object library Version 9.2 (COM component) to your project.This COM component provides various objects through we can access the outlook.

  1. Microsoft.Office.Interop.Outlook.Application
  2. Microsoft.Office.Interop.Outlook.Explorer
  3. Microsoft.Office.Interop.Outlook.Inspector
  4. Microsoft.Office.Interop.Outlook.MAPIFolder
  5. Microsoft.Office.Interop.Outlook.MailItem
  6. Microsoft.Office.Interop.Outlook.AppointmentItem
  7. Microsoft.Office.Interop.Outlook.TaskItem
  8. Microsoft.Office.Interop.Outlook.ContactItem 
1. Microsoft.Office.Interop.Outlook.Application

Using this class we can create an object ot the outlook application.

Microsoft.Office.Interop.Outlook.Application outlookApp = newMicrosoft.Office.Interop.Outlook.Application();

2. Microsoft.Office.Interop.Outlook.AppointmentItem

You can create an appointment using this class. You can not directly create an instance of this class. Because the AppointmentItemClass has not constructors defined so; you have to use the application object for create an instance of the appointment object.  For create an instance of the AppointmentItem object You have to use the Application object’s CreateItem() method. This method takesOlItemType enumuration parameter which has eight values.

(olAppointmentItem, olContactItem, olDistributionListItem, olJournalItem, olMailItem, olNoteItem, olPostItem, olTaskItem) and cast it to AppintmenItem type.
Microsoft.Office.Interop.Outlook.AppointmentItem oAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);

AppointmentItem object provides various properties.

Properties
Property
Description
Type
Subject
Set the subject of the appointment
String
Location
Location of the appointment
String
Body
Body of the appointment
String
Start
Set start date time of appointment
DateTime
End
Set end date time of appointment
DateTime
ReminderSet
Set whether reminder is on or off
Boolean
ReminderMinuteBeforeStart
Set the time period before reminder message is popup
Integer
ReminderPlaySound
Set the sound file path which play sound when reminder is active
String (Path)
Importance
Set the importance priority for appointment
OlImportance
BusyStatus
Set the status of appointment
OlBusyStatus
OlImportance enumeration takes three values

olImportanceHigh     ->   High importance
olImportanceLow     ->   Low importance
olImportanceNormal ->  Normal importance

OlBusyStatus enumeration takes four values

olBusy                  ->  Busy status
olFree                  ->  Free status
olOutOfOffice        ->  Out of office status
olTentative           ->  Tentative status (under terms not fully final) 

Methods:

Save()

This method save your appointment to your system. When you call the save() method an appointment is save to outlook.

ForwardAsVcal()

This method can be used to the Vcs file via email.

Microsoft.Office.Interop.Outlook.MailItem oMailItem = oAppointment.ForwardAsVcal();
oMailItem.To = “Destination mail id”;
oMailItem.Send() ;
The send method send the appointment via email.
The receipient receive the mail and press the save button the appointment is automatically add to his outlook.

//Create an instance of the Appilcation object
Microsoft.Office.Interop.Outlook.Application outlookApp = new Application();       

//Create and instance of the Appointment class 
Microsoft.Office.Interop.Outlook.AppointmentItem oAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);

//Set the various property of the appointmentitem object
oAppointment.Subject = "This is appointment Subject";
oAppointment.Body = "This is appointment body";
oAppointment.Location = "This is appointment location";
oAppointment.Start= Convert.ToDateTime("06/29/2006 10:00:00 AM");
oAppointment.End= Convert.ToDateTime("06/29/2006 10:00:00 AM");
oAppointment.ReminderSet = true;
oAppointment.ReminderMinutesBeforeStart = 15;
oAppointment.ReminderPlaySound = false;
oAppointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
oAppointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;   
   
//This method save the appointment to the outlook
oAppointment.Save();
       
//send a mail and appointment as an attachment to Ajay Rohilla
Microsoft.Office.Interop.Outlook.MailItem oMailItem = oAppointment.ForwardAsVcal();
oMailItem.To = "FirstName.LastName @t-systems.com";
oMailItem.Send();

READ MORE >>

0 comments: