none
[E2007/E2010/Exchange-Online] [EWSMA 1.1] [VB.Net]: [Sync'ing Contacts] RRS feed

  • Question

  • I am in the process of writing a 2 way sync for Contacts in my MS Exchange to our CRM product.

    I am able to insert and delete contacts in exchange, however I am running into difficulty updating contact items in exchange. Specifically, when I have an existing item in exchange, i simply bind to the contact using the ItemID.

     

    Dim contact As Contact = contact.Bind(_EXService, Item.ItemId, extendedPropertySet)
    
    I then set the properties of the contact to the values in my datarow. My problem arises when I set any of the email addresses to nothing.
    Dim email As New EmailAddress

    email.Address = nothing
    email.Name = nothing

    contact.EmailAddresses(EmailAddressKey.EmailAddress1) = email

     

    When I call the update method on the contact it throws an error:

    "Object reference not set to an instance of an object."

     

    I have tried setting:

     

    contact.EmailAddresses(EmailAddressKey.EmailAddress1) = nothing
    

     

    This does not error but has no effect on the values, It leave the previous value set.

     

    How do I update the email address fields when I need to set them to BLANK?


    Thanks Rob
    Wednesday, February 2, 2011 3:42 PM

All replies

  • MICROSOFT MODERATORS?? ANYONE??

    Is this a bug? Is it possible to clear the email address fields when updating a contact with EWS API??

     

    I really need some input on this!


    Thanks Rob
    Thanks Rob
    Monday, February 14, 2011 9:58 PM
  • Everyone here is the answer:

    Dim contact As New Contact(_EXService)
    Dim DispName__2 As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32896, MapiPropertyType.[String])
    Dim AddType As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32898, MapiPropertyType.[String])
    Dim EmailAdd As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32899, MapiPropertyType.[String])
    Dim OriginalDispName As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32900, MapiPropertyType.[String])
    Dim OriginalEntryId As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 32901, MapiPropertyType.Binary)

    Dim userFields As ExtendedPropertyDefinition() = New ExtendedPropertyDefinition() {DispName__2, AddType, EmailAdd, OriginalDispName, OriginalEntryId}

    Dim extendedPropertySet As New PropertySet(BasePropertySet.FirstClassProperties, userFields)

    contact = contact.Bind(_EXService, New ItemId(_ITEMID), extendedPropertySet)

    With contact

       .RemoveExtendedProperty(DispName__2)
       .RemoveExtendedProperty(AddType)
       .RemoveExtendedProperty(EmailAdd)
       .RemoveExtendedProperty(OriginalDispName)
       .RemoveExtendedProperty(OriginalEntryId)

       .Save(WellKnownFolderName.Contacts)
    End With
    Thanks Rob
    Tuesday, April 19, 2011 1:07 PM