Why the UserProperty's value not same between Outlook UI and code when update it by EWS API? RRS feed

  • Question

  • Hi

    I have change a UserProperty by EWS API . The property's value will auto change in the Outlook explorer mail list, but not changed when read it in codes.  Why this happen? How can I get the real value?


    This is the codes and steps:

    1. Open the Outlook, open a mail , and set the user property [MyMark] as "Mark by Outlook". VBS:

    Sub AddMyMark()
        Dim mail As MailItem
        Set mail = Application.ActiveInspector.CurrentItem
        mail.UserProperties.Add "MyMark", olText
        mail.UserProperties.Item("MyMark") = "Mark by Outlook."
    End Sub

    2. Edit the View setting, let the MyMark property show in the mail list, like as:

    3. Don't close the Outlook. Adn then run the EWS API code , this is part of my C# app.

    EmailMessage mail = EmailMessage.Bind(service, entryEwsId);
    ExtendedPropertyDefinition myMark = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "MyMark", MapiPropertyType.String);
    mail.Load(new PropertySet(myMark)); //Should be "Mark by Outlook"
    mail.SetExtendedProperty(myMark, "Mark by server");

    4. Watch the Outlook, The mail list will auto change the property value. But not change in codes.

    this is the VBS:   (only 1 mail there, so used Item(1))

    Sub ShowMyMark()
        Dim mail As MailItem
        Set mail = Application.ActiveExplorer.CurrentFolder.Items(1)
        MsgBox mail.UserProperties.Item("MyMark")
    End Sub

    Same problem in C# VSTO project.

    Close the outlook and open again. the value is sync.

    Please help.


    Tuesday, January 17, 2012 6:09 AM