Micorsoft for it's major applications provides a way of integrating with the exteranal application,Like exposing it as a COM component or throw web service.Now,In my case.I want to integrate the MS Outlook in a .NET Application.
As I know, Basically there are 4 ways to acieve it.
The types and members of the Microsoft.Office.Interop.Outlook namespace provide support for interoperability between the COM object model of Microsoft Outlook 2010 and managed applications that automate Outlook.
Outllok DLL reference is the best suited option of the stand alone applications.
Right click on the project and choose add reference option.
Add the namspace reference,In your class file.
using Microsoft.Office.Interop.Outlook;
In the below snippet of code,I am reading the Outlook Appointments for the given month.
private void OutlookCalendar(DateTime dt)
{
DataTable dtmaster = new DataTable();
try
{
Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;
oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;
string mes = string.Empty;
foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
if (item.IsRecurring == false)
{
DateTime temp = new DateTime(dt.Year, dt.Month + 1, 1);
DateTime enddate = temp.AddDays(-1);
if (item.Start.Date >= dt && item.Start.Date <= enddate)
{
DateTime startDt = item.Start;
DateTime endDt = item.End;
dtmaster.Rows.Add(item.Subject, item.Body, startDt, endDt, startDt.ToString("hh:mm") + " - " + endDt.ToString("hh:mm"), item.Location);
}
}
}
}
catch (System.Exception ex)
{
//logic to log the exception to your error log file
}
}
In my next blog,I will explain how to integrate outlook in ASP.NET application throw Exchange web service method(EWS).
As I know, Basically there are 4 ways to acieve it.
- Using Microsoft.Office.Interop.Outlook.dll
- WEDEV
- Exchange web services.
- Active directory services interface.
The types and members of the Microsoft.Office.Interop.Outlook namespace provide support for interoperability between the COM object model of Microsoft Outlook 2010 and managed applications that automate Outlook.
Outllok DLL reference is the best suited option of the stand alone applications.
Right click on the project and choose add reference option.
Add the namspace reference,In your class file.
using Microsoft.Office.Interop.Outlook;
In the below snippet of code,I am reading the Outlook Appointments for the given month.
private void OutlookCalendar(DateTime dt)
{
DataTable dtmaster = new DataTable();
try
{
Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;
oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
outlookCalendarItems = CalendarFolder.Items;
outlookCalendarItems.IncludeRecurrences = true;
string mes = string.Empty;
foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
{
if (item.IsRecurring == false)
{
DateTime temp = new DateTime(dt.Year, dt.Month + 1, 1);
DateTime enddate = temp.AddDays(-1);
if (item.Start.Date >= dt && item.Start.Date <= enddate)
{
DateTime startDt = item.Start;
DateTime endDt = item.End;
dtmaster.Rows.Add(item.Subject, item.Body, startDt, endDt, startDt.ToString("hh:mm") + " - " + endDt.ToString("hh:mm"), item.Location);
}
}
}
}
catch (System.Exception ex)
{
//logic to log the exception to your error log file
}
}
In my next blog,I will explain how to integrate outlook in ASP.NET application throw Exchange web service method(EWS).

No comments:
Post a Comment