none
Outlook Add-In: Outlook.StorageItem (adding UserProperties limitation?) RRS feed

  • Question

  • I am trying to add a User Property to a storage item for a calendar appointment.

    Essentially I am trying to keep track of events that have occured per item object in the calendar, so I am using the GlobalAppointmentID property to add the UserProperty.

    Like this:

            void SetEmailReminderIsSent(string GlobalAppointmentID)
            {
                Outlook.MAPIFolder selectedFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.StorageItem si = selectedFolder.GetStorage(GlobalAppointmentID, Outlook.OlStorageIdentifierType.olIdentifyBySubject) as Outlook.StorageItem;
                if (si.Size == 0)
                {
                    //gets to here and stops!
                    si.UserProperties.Add(GlobalAppointmentID/*.ToString()*/, Outlook.OlUserPropertyType.olYesNo);
                    si.UserProperties[GlobalAppointmentID/*.ToString()*/].Value = true;
                }
                else
                {
                    si.UserProperties[GlobalAppointmentID].Value = true;
                }
                System.Windows.Forms.MessageBox.Show("Email Reminder Is Sent Set To True");
            }

    The param passed to the function is this:

    SetEmailReminderIsSent(apptItem.GlobalAppointmentID);

    Where apptItem is type Outlook.AppointmentItem.

    I have added a comment where the function stops working. However, I added a breakpoint and ran in debug and the variable does have a legit value (although very long). Could it be there is a limit to the name param in UserProperty.add (name, etc etc)?

    When I substitute for a different string, like "JustATest" it actually works, so it must have something to do with the GlobalAppojntmentID variable.

    Does anybody have some experience or thoughts to share on this?

    Also, will even if I get this working, is this the best way to store info per calendar item? Is this going to cause a massive storage issue or break some other limit? If so, any suggestions?

    Monday, February 11, 2013 11:40 PM

Answers

  • Do not use a variable with a unique value as a custom property name!!!

    Named MAPI properties are a finite resource and their number is limited to 64k for store. Once you run out of them, your store is a toast.

    If you want to keep track of which appointments are processed and which are not, why not simply store all processed ids in a CR/LF separated list in a single property, named, say, "ProcessedIDs"?

    Also, UserProperties.Add returns a UserProperty object, there is no reason to use UserProperties[] to access retrieve it.


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

    Monday, February 11, 2013 11:56 PM
  • Retrieve the property to a string, convert it to an array using string.split. You can then loop through the array elements to see if the id is already there.

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

    Friday, February 15, 2013 5:49 PM

All replies

  • Do not use a variable with a unique value as a custom property name!!!

    Named MAPI properties are a finite resource and their number is limited to 64k for store. Once you run out of them, your store is a toast.

    If you want to keep track of which appointments are processed and which are not, why not simply store all processed ids in a CR/LF separated list in a single property, named, say, "ProcessedIDs"?

    Also, UserProperties.Add returns a UserProperty object, there is no reason to use UserProperties[] to access retrieve it.


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

    Monday, February 11, 2013 11:56 PM
  • Dmitry,

    Thank you very much for your reply. When I was starting this project, your name crept up lots when I was searching for help getting started.

    Your suggestion seems to make much sense, I was not aware of the limit. I certainly intend to take your approach, but I am still curious why it didn't actually work.

    I only started trying to use the .NET Framework and write C# code a few days ago. I have some novice experience in C++ and un-managed code. While I appreciate the suggestion, given my limited experience, would you be willing to show firstly how I might re-write the function to save the ID's (append the list), and secondly how I might iterate through it to check if if it present, please?

    I was previously doing this:

            bool getIsReminderSent(string GlobalAppointmentID)
            {
                bool value = false;
                Outlook.MAPIFolder selectedFolder = this.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.StorageItem si = selectedFolder.GetStorage(GlobalAppointmentID, Outlook.OlStorageIdentifierType.olIdentifyBySubject) as Outlook.StorageItem;
                if (si.Size == 0)
                {
                    value = false;
                }
                else
                {
                    value = (bool)si.UserProperties[GlobalAppointmentID].Value;
                }
                System.Windows.Forms.MessageBox.Show("return value is " + value);
                return value;
            }

    Also, is it completely safe to cast Outlook.OlUserPropertyType.olYesNo to bool?


    • Edited by reb00b Tuesday, February 12, 2013 12:12 AM
    Tuesday, February 12, 2013 12:11 AM
  • Retrieve the property to a string, convert it to an array using string.split. You can then loop through the array elements to see if the id is already there.

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

    Friday, February 15, 2013 5:49 PM