![]() |
Enterprise Systems »
Office Development »
Outlook
Advanced
License: The Code Project Open License (CPOL)
Import and Export Outlook Appointments (using JavaScript)By Sandeep MewaraHow to import and export appointments from Outlook on client-side via JavaScript (for a web application hosted on the server). |
C#, Javascript, HTML, Windows, .NET, ASP.NET, VS2005, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

This article illustrates an example of how to import and export appointments from an Outlook application installed on the client machine and a web-application on the server. The web application being hosted on the server, extraction of appointments can not be done on the server-side as every other user has his/her own list of appointments stored in their Outlook.
I was working on a project that had a requirement to import and export appointments from an Outlook application: saving appointments on the client machine as per the client's choice, and porting appointments from Outlook appointments into the web-application. I tried to find help on the Internet for the same, but failed to find any article written on it.
Since we need to extract the appointments on the client-side, we will be using an ActiveX object. Thus, we need to enable the setting to allow ActiveX scripts, as shown below (found under Security Settings of Internet Options):

Once an Outlook application is installed on the system and the security setting is done as per above, we are ready to import/export appointments.
// create outlook object
var objOutlook = new ActiveXObject( "Outlook.Application" );
In the case of exporting: for the different items in Outlook, there are fixed item numbers, like:
var olAppointmentItem = 1; //fixed for different properties of outlook object
var objAppointment = objOutlook.CreateItem(olAppointmentItem);
Now, the properties of this object can be set as per required and then saved.
objAppointment.Subject = "Appointment exported to Outlook from a web application";
.....
objAppointment.Duration = duration;
objAppointment.Save();
In the case of import: again, for the different items in Outlook, there are fixed item numbers, like:
var outlookFolderCalendar = 9;
We will get all the appointments after creating the MAPI namespace, and give the default folder name.
var objNameSpace = objOutlook.GetNamespace("MAPI");
var outlookFolder = objNameSpace.GetDefaultFolder(outlookFolderCalendar);
var myOutlookItems = outlookFolder.Items;
For example, I have to show the first appointment in the calendar. The different properties can be extracted like:
var dateOfAppointment = myOutlookItems(1).Start;
.....
var bodyOfAppointment = myOutlookItems(1).Body;
The extracted values of each appointment can now be used as per your needs. One thing to note is while extracting appointments from Outlook, we get a prompt like shown below:

We need to allow access in order to get the appointments from Outlook.
Since I was using an ActiveX object, it was difficult getting the different property names required, as ActiveX objects cannot be debugged for quick-watch. It was fun and irritating at the same time to find all the properties required. Not to forget the case-sensitive nature of JavaScript!
First version.
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 24 Sep 2008 Editor: Smitha Vijayan |
Copyright 2007 by Sandeep Mewara Everything else Copyright © CodeProject, 1999-2010 Web10 | Advertise on the Code Project |