How to: Create a Task Item

This example shows how to create a task item by using the MarkAsTask(OlMarkInterval) method.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

In the following code example, CreateToDoItemExample creates a to-do item by calling the MarkAsTask method on the item and then saving the item. The example marks the item for follow-up tomorrow and sets a reminder for tomorrow at 10:00 A.M. by using the ReminderSet and ReminderTime properties. The example then uses the Save() method to save the item.

If you use Microsoft Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 14.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void CreateToDoItemExample()
    // Date operations
    DateTime today = DateTime.Parse("10:00 AM");
    TimeSpan duration = TimeSpan.FromDays(1);
    DateTime tomorrow = today.Add(duration);
    Outlook.MailItem mail = Application.Session.
        "[MessageClass]='IPM.Note'") as Outlook.MailItem;
    mail.TaskStartDate = today;
    mail.ReminderSet = true;
    mail.ReminderTime = tomorrow;

Other Resources