1
votes

I have an old VB6 application that creates Outlook contacts using MAPI and I am in the process of converting it to VB .NET 2010.

The VB6 application allows me to access properties by name using the ItemProperties property, for example:

objContact.ItemProperties(strPropertyName) = "Accountant"

I can see ItemProperties in the extended property list but I cannot work out how to access it. Other posts show how to access extended properties for existing contacts but I am trying to create new a contact.

Is it possible to set properties dynamically as you could in MAPI? If not I will end up with a very large CASE statement i.e.

Select Case strPropertyName
 Case "JobTitle"
  ...
 Case "Title"
  ...
End Select
1

1 Answers

0
votes

Here is a simple example of creating a Contact in EWS and using ExtendedProperties. You need to make use of the SetExtendedProperty method, passing in the appropriate ExtendedPropertyDefinition.

var titleDef = new ExtendedPropertyDefinition(0x3A45, MapiPropertyType.String);

Contact contact = new Contact(service);
contact.GivenName = "George";
contact.Surname = "Washington";
contact.FileAsMapping = FileAsMapping.SurnameSpaceGivenName;
contact.CompanyName = "U.S.A";
contact.PhoneNumbers[PhoneNumberKey.BusinessPhone] = "555-234-1231";
contact.EmailAddresses[EmailAddressKey.EmailAddress1] = "[email protected]";
contact.EmailAddresses[EmailAddressKey.EmailAddress1].Name = "G. Washington";
contact.SetExtendedProperty(titleDef, "President");
contact.Save();
var contactID = contact.Id;