Using InfoPath to create tasks and appointments in Outlook

by S.Y.M. Wong-A-Ton

Learn how you can use the Outlook Object Model in InfoPath to create Outlook appointments and tasks.

In a timespan of 2 weeks, questions have been popping up about how to use InfoPath to create Outlook tasks and appointments.

I don’t usually do any Outlook programming, but since these questions were being asked frequently, I’ve decided to tackle the issue.

InfoPath does not provide any support for creating Outlook tasks or appointments, so if you want to create a task, appointment, or any other object in Outlook, you can use the Outlook Object Model to do so.

Suppose you’ve created an InfoPath form template with 2 date fields named startDate and endDate, 2 time fields named startTime and endTime, and 3 text fields named subject, body, and location. Add a button to the InfoPath form template and create a Clicked event handler for it.

The code for each of the solutions described below should go in the Clicked event handler for the button. The solutions work for forms filled out through the InfoPath client application and for adding appointments and tasks to one’s own calendar and tasks list in Outlook.

Use InfoPath to create an Outlook appointment

There are 2 ways you can use an InfoPath form to create an Outlook appointment:

  1. Write code that adds an AppointmentItem to the calendar in Outlook.
  2. Convert the InfoPath form to a vCalendar file, open the file, and then save the appointment in Outlook.

Where the first method is concerned, you could use the following base article from the Microsoft Support web site: How to create an appointment by using Outlook Object Model in Microsoft Visual Basic .NET. I’ve converted the code from the preceding article to C#. You can download the code.

Where the second method is concerned, you’d have to use the data from the InfoPath form and create a text file with a .vcs extension. The code I’ve written converts data from an InfoPath form, writes it to a local file, and then automatically opens the file so that it can be saved as an appointment in Outlook.

Note: You’ll have to give your InfoPath form template Full Trust for it to work with the code.

Use InfoPath to create an Outlook task

Outlook tasks can be created similarly to appointments. The only difference is that you’ll have to use a TaskItem object instead of an AppointmentItem object. You can download the code.

Note: You’ll have to give your InfoPath form template Full Trust for it to work with the code.

 Subscribe (RSS | Email)

Related Posts

Comments to this post were closed 30 days after it was published.

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. Usage of techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.

Working with InfoPath