none
[E2007] [EWSMA] [C#]: how to simply clear email/phone/address contact's fields? RRS feed

  • Question

  • Hi there,

    I'm doing some dev using Exchange Web Service Managed API. I've first used the 1.1 beta, and recently the 1.1 final.
    I'm testing against an Exchange 2007 server.

    Coming back with a question already posted on the forum, but without any clear answer: how to simply clear email / phone number or adress fields for a contact?

    For example, I would like to do this:

    var ctu = Contact.Bind(service, "xxx");
    ctu.EmailAddresses[EmailAddressKey.EmailAddress1] = "";
    ctu.Update(ConflictResolutionMode.AlwaysOverwrite);

    But I'm always getting the exception: An object within a change description must contain one and only one property to modify.

    As described in some other posts, I've tried some solution like this one:

                var Email1DisplayProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 0x8080, MapiPropertyType.String);
                var Email1AddrTypeProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 0x8082, MapiPropertyType.String);
                var Email1Prop = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 0x8083, MapiPropertyType.String);
                var Email1OrgdisplayProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 0x8084, MapiPropertyType.String);
                var Email1EntryIDProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Address, 0x8085, MapiPropertyType.Binary);

                var pps = new PropertySet(PropertySet.IdOnly);
                pps.Add(Email1DisplayProp);
                pps.Add(Email1AddrTypeProp);
                pps.Add(Email1Prop);
                pps.Add(Email1OrgdisplayProp);
                pps.Add(Email1EntryIDProp);

                var ctu = Contact.Bind(service, "xxx=", pps);
                ctu.RemoveExtendedProperty(Email1DisplayProp);
                ctu.RemoveExtendedProperty(Email1AddrTypeProp);
                ctu.RemoveExtendedProperty(Email1Prop);
                ctu.RemoveExtendedProperty(Email1OrgdisplayProp);
                ctu.RemoveExtendedProperty(Email1EntryIDProp);
                ctu.Update(ConflictResolutionMode.AlwaysOverwrite);

    but sincerely, how many lines of codes just to clear a field!

    I thought the 1.1 final would have fixed this, but it seems not.

    Thanks for your help!
    Alex

     

    Monday, November 22, 2010 5:22 PM

All replies

  • Hello Alex,

    Setting the field to null works. The Exchange Web Services Managed API translates that in to a DeleteItemField update.

    var ctu = Contact.Bind(service, "xxx");
    ctu.EmailAddresses[EmailAddressKey.EmailAddress1] = <strong>null</strong>;
    ctu.Update(ConflictResolutionMode.AlwaysOverwrite);
    
    
    

    Michael | Microsoft Exchange SDK
    Monday, November 22, 2010 8:13 PM
    Moderator
  • Hi Michael,

    Thanks for your answer.
    This works great for phone numbers and physical addresses but not for email addresses.

    The update generates the following DeleteItemField:
    <t:DeleteItemField>
        <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress1" />
    </t:DeleteItemField>

    but it seems it is not enough. When I look at the contact again in Outlook or OWA, the email address is still present.
    Looking more in details with OutlookSpy, the Email1Address (ID=0x8083) field was cleared, but not the other related fields: Email1AddressType (ID=0x8082), Email1DisplayName (ID=0x8080), Email1EntryID (ID=0x8085).

    Setting an email address to null shouldn't be be translated to a DeleteItemField for all corresponding Email address fields (DisplayName, AddressType and EntryID)?

    Alex

     

    Tuesday, November 23, 2010 9:41 AM
  • Alex,

    Did you find a work around for this?

    I have been fighting the same thing since January...

    Thanks


    Thanks Rob
    Friday, April 1, 2011 4:50 PM
  • Hi Alex,

    you must add the addressEmail to your PropertySet and then set it to null.

    var pps = new PropertySet(PropertySet.IdOnly);      
    pps.Add(Email1DisplayProp);      
    pps.Add(Email1AddrTypeProp);      
    pps.Add(Email1Prop);      
    pps.Add(Email1OrgdisplayProp);      
    pps.Add(Email1EntryIDProp);       
    
    //add EmailAddress to propertySet
    WsContactProperties.lightProperties.Add(ContactSchema.EmailAddress1);
    
    var ctu = Contact.Bind(service, "xxx=", pps);
    
    //set the emailAddress to null
    ctu.EmailAddresses[EmailAddressKey.EmailAddress1] = null;
    
    ctu.RemoveExtendedProperty(Email1DisplayProp);
    ctu.RemoveExtendedProperty(Email1AddrTypeProp); 
    ctu.RemoveExtendedProperty(Email1Prop); 
    ctu.RemoveExtendedProperty(Email1OrgdisplayProp); 
    ctu.RemoveExtendedProperty(Email1EntryIDProp);
    ctu.Update(ConflictResolutionMode.AlwaysOverwrite);
    
    
    

     

    Monday, July 18, 2011 3:28 PM
  • On another thread on this subject someone recently posted another possible fix.

     

    Here is the thread:

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/b57736cf-b007-49f6-b8c6-c4ba00b5cc23/

     

    Here s what was posted:

    contact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress("@");

    Thanks Rob
    Monday, July 18, 2011 3:33 PM