none
Storing data in UserProperties vs PropertyAccessor - properties not persisting RRS feed

  • Question

  • Hi,

    I don't know if I'm doing something wrong, but setting properties on an AppointmentItem using PropertyAccessor.SetProperty doesn't persist across to invitees calendars, whereas using UserProperties does. They both save and persist to the organizer calendar.

    Example:

    UserProperties //works

    Outlook.ItemProperties properties = this._Appointment.ItemProperties;
    
                try
                {
                    Outlook.ItemProperty textProperty = properties.Add(name, Outlook.OlUserPropertyType.olText, false);
                    textProperty.Value = value;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Property " + name + " could not be saved: " + ex.ToString());
                }
    

    PropertyAccessor //doesn't work

    try
                {
                    string propertySchema = "http://schemas.microsoft.com/mapi/string/" + "{FFF40745-D92F-4C11-9E14-92701F001EB3}/" + name;
                    this._Appointment.PropertyAccessor.SetProperty(propertySchema, value);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Property " + name + " could not be saved: " + ex.ToString());
                }

    Am I using PropertyAccessor wrong?

    I have tried to switch to using PropertyAccessor because Outlook prints out all the User Properties and there is no way to prevent that.

    Or am I better off just giving up on using Outlook to store custom data? The last resort is storing this in some sort of database, I'd rather not do that and keep it within Outlook

    Tuesday, February 14, 2017 11:58 AM

All replies

  • Hello John,

    The Outlook object model supports creating and storing solution data as hidden items in a folder. You can use Folder.GetStorage to create a StorageItem object in a specified folder. You can identify this object by the subject, message class, or Entry ID. Solutions can create StorageItem objects in all folders except when:

    • The folder is a Microsoft Exchange public folder, an Internet Message Access Protocol (IMAP), MSN Hotmail, or a Microsoft SharePoint Foundation folder.

    • The user permission for the folder is read-only.

    • The store provider does not support hidden items.

    In these cases, Folder.GetStorage will return an error: "Cannot create StorageItem in this folder." Read more about that in the Creating and Saving Data to Solution Storage article.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, February 14, 2017 4:04 PM
  • Hi Eugene,

    Thanks ... I have also read this:

    https://msdn.microsoft.com/en-us/library/office/ff869128.aspx?f=255&MSPPError=-2147217396

    which states:

    GetStorage returns an error if the store type of the folder is not supported. The following stores return an error when GetStorage is called:

    • Hotmail store

    • Internet Message Access Protocol (IMAP) stores

    • Delegate stores

    • Public folder stores

    Delegate stores is an issue, as I'd need anyone who has delegate access to a calendar to be able to see the data set by the organizer (and for them to update that data if they choose to)


    Tuesday, February 14, 2017 4:35 PM
  • So do StorageItems carry across to invitees on meeting requests? I'm guessing not given they store on the folder ..
    Tuesday, February 14, 2017 4:52 PM
  • Hi,

    I tested with the following code to check if it works using PropertyAccessor.SetProperty. I got the same result as you. I think storing data in database is a better workaround.

    Sub AppointmentItemPropertyAccessorSetProperty()
     Dim myProp As String
     Dim myValue As Variant
     Dim oAppointmentItem As Outlook.AppointmentItem
     Dim oPA As Outlook.PropertyAccessor
     Dim oMail As Outlook.MeetingItem
     'Get first item in the inbox
     Set oAppointmentItem = ActiveInspector.CurrentItem
     'Set oMail = ActiveInspector.CurrentItem
     
     Debug.Print oAppointmentItem.Subject
     'Application.Session.GetDefaultFolder(olapp).Items(1)
     'Name for custom property using the MAPI string namespace
     myProp = "http://schemas.microsoft.com/mapi/string/" & _
     "{FFF40745-D92F-4C11-9E14-92701F001EB3}/myCustomer"
     myValue = "Dan Wilson"
     On Error GoTo ErrTrap
     Set oPA = oAppointmentItem.PropertyAccessor
     Debug.Print oPA.GetProperty(myProp)
     'oPA.SetProperty myProp, myValue
     'Debug.Print oPA.GetProperty(myProp)
    
     'Save the item
     'oAppointmentItem.Save
     Exit Sub
    ErrTrap:
     Debug.Print Err.Number, Err.Description
    End Sub

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 16, 2017 7:38 AM
    Moderator