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.
- In the Solution Explorer, right-click the EWSMA_ExtendedProperties project and select Set as StartUp Project.
- Open the EWSMA_ExtendedProperties project.
- In Solution Explorer, open the app.config file.
- 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.
- Navigate to TODO: 5.2.1.
- 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”.
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.
- Navigate to TODO: 5.2.2.
- Un-comment code surrounded by /* … */ block to display the search results.
Add the following code after the TODO: 5.2.2 comment. This finds all appointments in your Calendar with the “Customer ID” extended property.
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);
- Go to Debug >> Start Without Debugging or press [CTRL]+[F5] to start the application.
- Press “1” to create an appointment with the “Customer ID” extended property.
- Open Outlook 2010 and verify that the appointment is in the Calendar. The extended property is not visible in Outlook.
- Press “2” to view appointments with the “Customer ID” extended property.
Verify that the appointment created previously displays with the “Customer ID” value of “General Industries”.
- Close the console application.