none
User Properties RRS feed

  • Question

  • It is my understanding that code will error if you try to access a user property that doesn't exist i.e

    app.UserProperties.Find("oGID", true).Value

    so I have the relevent code

                        if (app.UserProperties.Find("oGID", true) == null)
                        {
                            app.UserProperties.Add("oGID", Outlook.OlUserPropertyType.olText, true, Outlook.OlUserPropertyType.olText);
                        }
                        app.UserProperties.Find("oGID", true).Value = app.GlobalAppointmentID;

    to create the relevent property if it doesn't exist before assigning a value to it, is there a better way to do this?

    Thanks

    Wednesday, April 18, 2012 4:05 PM

Answers

  • Keep in mind that Add returns UserProperty object. Your code ignores the returned value.

    Alos note that you can call UserProperties.Add even if the property already exists and you won't get a duplicate:

    UserProperty prop = app.UserProperties.Add(...);

    prop.Value = app.GlobalAppointmentID;

    
    

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    • Marked as answer by Vis Xero Friday, April 20, 2012 9:42 AM
    Wednesday, April 18, 2012 4:40 PM

All replies