Exercise 2: Working with Extended Properties

Task 1 – Beginning the Exercise

In this task, you will open the project and configure it to run with your accounts.

  1. In the Solution Explorer, right-click the EWSMA_ExtendedProperties project and select Set as StartUp Project.
  2. Open the EWSMA_ExtendedProperties project.
  3. In Solution Explorer, open the app.config file.
  4. Change the PrimaryLabUserId and SecondaryLabUserId values to your primary and secondary lab accounts.

Task 2 – Create Items and Extended Properties

In this task, you will create an extended property, attach it to an appointment, and set its value.

  1. Navigate to TODO: 5.2.1.
  2. Add the following code after the TODO: 5.2.1 comment. This defines a “Customer ID” property for an appointment and assigns the property the value “12345”.

    C#

    ExtendedPropertyDefinition extendedProperty = new ExtendedPropertyDefinition( DefaultExtendedPropertySet.Appointment, _extendedPropertyName, MapiPropertyType.String); appointment.SetExtendedProperty(extendedProperty, _customerId); appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

Task 3 – Finding Items with Extended Properties

In this task, you will use the Extended Property defined above to find the Appointment you created.

  1. Navigate to TODO: 5.2.2.
  2. Un-comment code surrounded by /* … */ block to display the search results.
  3. Add the following code after the TODO: 5.2.2 comment. This finds all appointments in your Calendar with the “Customer ID” extended property.

    C#

    ItemView itemView = new ItemView(10); ExtendedPropertyDefinition extendedProperty = new ExtendedPropertyDefinition( DefaultExtendedPropertySet.Appointment, _extendedPropertyName, MapiPropertyType.String); itemView.PropertySet = new PropertySet( BasePropertySet.IdOnly, ItemSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, extendedProperty); SearchFilter filter = new SearchFilter.Exists(extendedProperty); FindItemsResults<Item> appointments =_service.FindItems( WellKnownFolderName.Calendar, filter, itemView);

  4. Go to Debug >> Start Without Debugging or press [CTRL]+[F5] to start the application.
  5. Press “1” to create an appointment with the “Customer ID” extended property.
  6. Open Outlook 2010 and verify that the appointment is in the Calendar. The extended property is not visible in Outlook.
  7. Press “2” to view appointments with the “Customer ID” extended property.
  8. Verify that the appointment created previously displays with the “Customer ID” value of “General Industries”.

  9. Close the console application.