Click here to Skip to main content
Licence CPOL
First Posted 7 May 2007
Views 77,004
Downloads 419
Bookmarked 64 times

Import and Export Outlook Appointments (using JavaScript)

By | 24 Sep 2008 | Article
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.

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

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)

About the Author

Sandeep Mewara

Software Developer (Senior)

India India

Member

He did his B.Tech from IIT Kharagpur.
Currently in Bangalore.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionkdjshfkds Pinmembersiphosmall20:18 15 Jan '12  
QuestionFetch all the appointments Pinmemberserafen14:28 11 Mar '11  
AnswerRe: Fetch all the appointments PinmvpSandeep Mewara20:12 11 Mar '11  
GeneralRe: Fetch all the appointments [modified] Pinmemberserafen2:44 12 Mar '11  
GeneralMessage Automatically Removed PinmemberAshish Tyagi 409:28 15 Jan '11  
QuestionExtra Work? PinmemberShaun Baines13:58 17 Dec '10  
QuestionOutLook 2007 Calendar Type Control Pinmemberlatell23:05 15 Oct '09  
Questionnot working in Safari & Mozila Pinmemberamit72118:52 27 Apr '09  
AnswerRe: not working in Safari & Mozila PinmemberSandeep Mewara19:17 9 Jun '09  
GeneralRe: not working in Safari & Mozila Pinmemberamit72120:35 25 Jun '09  
GeneralUrgently Required ....... Pinmembertrushitshah20:49 23 Apr '09  
AnswerRe: Urgently Required ....... PinmemberSandeep Mewara19:18 9 Jun '09  
GeneralRe: Urgently Required ....... Pinmembertrushitshah20:01 9 Jun '09  
QuestionUrgently required PinmemberMeCode119:39 22 Apr '09  
AnswerRe: Urgently required PinmemberSandeep Mewara19:21 9 Jun '09  
QuestionThis code works well and good in IE7. But its not working in IE6. Pinmembersannu_eshwari19:36 1 Apr '09  
AnswerRe: This code works well and good in IE7. But its not working in IE6. PinmemberSandeep Mewara19:22 9 Jun '09  
GeneralThank u ur code is great PinmemberManprit.bagga18:05 5 Mar '09  
AnswerRe: Thank u ur code is great PinmemberSandeep Mewara19:23 9 Jun '09  
GeneralRe Import and Export Outlook appointments using javascript Pinmemberbsidey20:38 10 Jan '09  
AnswerRe: Re Import and Export Outlook appointments using javascript PinmemberSandeep Mewara19:13 18 Jan '09  
GeneralFinding outlook and exporting an event to the outlook Pinmembernainakarri4:09 17 Dec '08  
AnswerRe: Finding outlook and exporting an event to the outlook PinmemberSandeep Mewara22:05 21 Dec '08  
GeneralRe: Finding outlook and exporting an event to the outlook Pinmembernainakarri3:58 26 Dec '08  
AnswerRe: Finding outlook and exporting an event to the outlook PinmemberSandeep Mewara23:44 26 Dec '08  
Ok.
 
You were not very clear, seems like you had some other problem (in the way you used to do the current requirement) which you said in your reply.
 
What i wanted to say was, since it is an admin update - it would had been better for you to provide a desktop application doing this for you. (Instead of Web App!)
 
Still if you need to do it though web, do tell, i will try to help you with the code that can send appointments to others calendar (assuming all security permissions are taken care) via Javascript for Web Applications.
 
Btw...yourself Naina or Usha! Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120529.1 | Last Updated 24 Sep 2008
Article Copyright 2007 by Sandeep Mewara
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid