How to create recurring tasks using Exchange Web Services for Exchange 2007/2010?


Earlier i got a chance to play around creating recurring tasks. I followed the article from MSDN and it worked like charm for me.

public TaskType CreateRecurringTask()
{
    // Create the task item and set property values.
    TaskType task = new TaskType();
    task.Subject = "Recurring Task";
    task.Body = new BodyType();
    task.Body.BodyType1 = BodyTypeType.Text;
    task.Body.Value = "Occurs every week";
    task.StartDate = DateTime.Now;
    task.StartDateSpecified = true;
 
    // Create the regeneration pattern.
    WeeklyRegeneratingPatternType regenerationPattern = new WeeklyRegeneratingPatternType();
    regenerationPattern.Interval = 1;
 
    // Define the recurrence pattern.
    NoEndRecurrenceRangeType recurrenceRange = new NoEndRecurrenceRangeType();
    recurrenceRange.StartDate = task.StartDate;
 
    // Set the regeneration and recurrence patterns.
    TaskRecurrenceType recurrence = new TaskRecurrenceType();
    recurrence.Item = regenerationPattern;
    recurrence.Item1 = recurrenceRange;
 
    task.Recurrence = recurrence;
 
    // Create the request to make a new task item.
    CreateItemType createItemRequest = new CreateItemType();
    createItemRequest.Items = new NonEmptyArrayOfAllItemsType();
    createItemRequest.Items.Items = new ItemType[1];
    createItemRequest.Items.Items[0] = task;
 
    // Send the request and receive the response.
    CreateItemResponseType createItemResponse = this.Service.CreateItem(createItemRequest);
 
    // Access a response message.
    ItemInfoResponseMessageType responseMessage = createItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
 
    // Return the new task item.
    return responseMessage.Items.Items[0] as TaskType;
}
 
public ExchangeServiceBinding Service
{
    get
    {
        if (this.service == null)
        {
            this.service = new ExchangeServiceBinding();
            this.service.Credentials = new NetworkCredential(
                this.UserName,
                this.Password,
                this.Domain);
            this.service.Url = this.Url; 
 
            // Set the request version.
            this.service.RequestServerVersionValue = new RequestServerVersion();
            this.service.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;
 
            // Specify the time zone for the DateTime properties of tasks.
            TimeZoneDefinitionType tzdt = new TimeZoneDefinitionType();
            tzdt.Id = "Eastern Standard Time";
            TimeZoneContextType tzct = new TimeZoneContextType();
            tzct.TimeZoneDefinition = tzdt;
            this.service.TimeZoneContext = tzct;
        }
        return this.service;
    }
}
Skip to main content