Click here to Skip to main content
15,890,512 members
Articles / Web Development / HTML
Article

Import and Export Outlook Appointments (using JavaScript)

Rate me:
Please Sign up or sign in to vote.
4.74/5 (50 votes)
24 Sep 2008CPOL2 min read 180.7K   1.2K   66   46
How to import and export appointments from Outlook on client-side via JavaScript (for a web application hosted on the server).

Screenshot - OutlookDemo2.png

Introduction

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.

Background

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.

Using the code

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):

Screenshot - OutlookDemo1.png

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.

JavaScript
// 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:

JavaScript
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.

JavaScript
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:

JavaScript
var outlookFolderCalendar = 9;

We will get all the appointments after creating the MAPI namespace, and give the default folder name.

JavaScript
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:

JavaScript
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:

Screenshot - Outlookdemo3.png

We need to allow access in order to get the appointments from Outlook.

Points of Interest

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!

History

First version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Intuit India
India India


A software professional for more than 17+ years building solutions for Web and Desktop applications.

Currently working at Intuit India.

Website: Learn By Insight
Github: Sandeep Mewara
LinkedIn: Sandeep Mewara

Strongly believe in learning and sharing knowledge.



Comments and Discussions

 
GeneralRe: Finding outlook and exporting an event to the outlook Pin
nainakarri26-Dec-08 3:58
nainakarri26-Dec-08 3:58 
AnswerRe: Finding outlook and exporting an event to the outlook Pin
Sandeep Mewara26-Dec-08 23:44
mveSandeep Mewara26-Dec-08 23:44 
GeneralRe: Finding outlook and exporting an event to the outlook Pin
nainakarri27-Dec-08 2:19
nainakarri27-Dec-08 2:19 
AnswerRe: Finding outlook and exporting an event to the outlook Pin
Sandeep Mewara29-Dec-08 17:25
mveSandeep Mewara29-Dec-08 17:25 
Generalget all messages [modified] Pin
testnoem4-Sep-08 22:48
testnoem4-Sep-08 22:48 
AnswerRe: get all messages Pin
Sandeep Mewara25-Sep-08 19:12
mveSandeep Mewara25-Sep-08 19:12 
GeneralImport & Export Outlook Pin
user user28-Aug-08 4:35
user user28-Aug-08 4:35 
GeneralRe: Import & Export Outlook Pin
testnoem4-Sep-08 22:41
testnoem4-Sep-08 22:41 
QuestionCan we search for contacts?? Pin
chiragkothari10-May-08 19:21
chiragkothari10-May-08 19:21 
AnswerRe: Can we search for contacts?? Pin
Sandeep Mewara13-Jul-08 21:06
mveSandeep Mewara13-Jul-08 21:06 
QuestionItem numbers Pin
vinaybv613-Mar-08 23:30
vinaybv613-Mar-08 23:30 
AnswerRe: various outlook event, properties, constants and etc... Pin
meaningoflights12-Apr-08 15:17
meaningoflights12-Apr-08 15:17 
Questioncontacts Pin
meaningoflights19-Feb-08 14:44
meaningoflights19-Feb-08 14:44 
AnswerRe: contacts - to anyone else needing it - here it is:) Pin
meaningoflights20-Feb-08 11:00
meaningoflights20-Feb-08 11:00 
QuestionHow to delete a particular instance of a recurring appointment using Javascript? Pin
Ramakrishnan Mohanraj4-Oct-07 19:27
Ramakrishnan Mohanraj4-Oct-07 19:27 
AnswerRe: How to delete a particular instance of a recurring appointment using Javascript? Pin
Sandeep Mewara4-Oct-07 19:41
mveSandeep Mewara4-Oct-07 19:41 
Generaldate time format Pin
tomcat53-Sep-07 4:42
tomcat53-Sep-07 4:42 
GeneralRe: date time format Pin
Sandeep Mewara3-Sep-07 19:19
mveSandeep Mewara3-Sep-07 19:19 
GeneralRe: date time format Pin
serafen12-Mar-11 11:30
serafen12-Mar-11 11:30 
GeneralTasks Pin
jammer122114-May-07 17:45
jammer122114-May-07 17:45 
GeneralRe: Tasks Pin
Sandeep Mewara20-May-07 20:38
mveSandeep Mewara20-May-07 20:38 

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.