Improving Outlook Performance (Part I): Video and Sample Add-In to Show Setting and Getting Multiple Custom Properties

Microsoft Outlook supports properties for items and folders. For example, a MailItem object has built-in properties such as the To, Subject, and Body properties, and a Folder object has built-in properties such as the Name and CurrentView properties. Developers can create custom properties for items and folders as well.

Improving performance has been a major goal in Microsoft Office Outlook 2007 and Microsoft Outlook 2010. Outlook provides the following objects to add, remove, enumerate, get, and set built-in properties and custom properties:

· The ItemProperties and ItemProperty objects

· The UserProperties and UserProperty objects

· The UserDefinedProperties and UserDefinedProperty objects

· The PropertyAccessor object, which was introduced in Outlook 2007.

Follow these best practices when accessing Outlook properties to improve performance on Outlook:

· Use ItemProperties and ItemProperty to enumerate explicit built-in properties and custom properties, and get and set custom properties for items (except for DocumentItem object).

· Use UserProperties and UserProperty to enumerate, get and set custom properties for items (except for the DocumentItem object).

· Use UserDefinedProperties and UserDefinedProperty to add and remove custom properties for folders.

· Use PropertyAccessor to get and set custom properties for the DocumentItem object, built-in item-level properties that are not exposed in the Outlook object model, or properties for the following objects: AddressEntry, AddressList, Attachment, ExchangeDistributionList, ExchangeUser, Folder, Recipient, and Store.

· To get or set multiple custom properties, use the PropertyAccessor object instead of the UserProperties object for better performance.

· To get or set multiple properties, use PropertyAccessor.GetProperties and PropertyAccessor.SetProperties, as opposed to repeated PropertyAccessor.GetProperty and PropertyAccessor.SetProperty, for better performance.

· To set for the first time a property created by the UserProperties.Add method, use the UserProperty.Value property instead of the SetProperties and SetProperty methods of the PropertyAccessor object.

Recently we published a visual how-to Efficiently Getting and Setting Custom Properties in a Contact Folder in Outlook 2010, that shows a very common scenario – an add-in populating a custom form that contains built-in and custom properties, and importing and exporting multiple property values between a file and an Outlook folder. The add-in specifies the following:

· A custom contact message class IPM.Contact.Sales Opportunity.

· A custom form, Sales Opportunity, to display contacts of this custom message class. The custom form defines fields that correspond to and display values of custom properties described in (c) below.

The add-in shows how to do the following tasks:

a) Create a custom folder, Opportunities, for contacts of this custom message class.

b) Set the Sales Opportunity form as the default form for the Opportunities folder.

c) Use UserDefinedProperties.Add to create 5 custom properties for this folder, of various data types including DateTime, double, string, integer, and Boolean.

d) Import data for contacts from a file, create a contact, and use a single call to PropertyAccessor.SetProperties to initialize 5 built-in properties and 5 custom properties for each contact in the Opportunities folder.

e) Export data from the Opportunities folder to a file, by using a single call to PropertyAccessor.GetProperties to get the values of multiple built-in and custom properties for each contact in the folder. The add-in shows how to reference some built-in properties by the MAPI proptag namespace, and custom properties by the MAPI string namespace.

View the video and download the add-in to try out the scenario!

See the following topics for more information about Outlook properties:

 

Properties Overview

Referencing Properties by Namespace

Creating a Property

Deleting a Property

Getting the Value of a Property

Setting the Value of a Property

Best Practices for Getting and Setting Properties