Export (0) Print
Expand All

How to: Access Solution-Specific Data Stored as a Hidden Message in a Folder

This example shows how to use the StorageItem object to retrieve data that is stored as a hidden message of a specific message class in a folder.

The StorageItem object is typically used to hide solution-specific data that cannot be displayed programmatically. In an Exchange environment, the StorageItem object is used to roam solution settings and ensure that these settings are available online and offline. You can assign a custom message class to the StorageItem object, or identify the object by subject.

The following code sample retrieves the XML data that is stored as a hidden message in the Calendar folder with the message class equal to IPM.Configuration.WorkHours.

The PropertyAccessor object returns the XML as an object that contains a byte stream rather than a string representation of the XML. The code sample uses System.Text.Encoding.Ascii.GetString to convert the byte stream to a string.

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The Imports or using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following lines of code show how to do the import and assignment in Visual Basic and C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private string GetWorkHoursXML()
{
    try
    {
        Outlook.StorageItem storage =
            Application.Session.GetDefaultFolder(
            Outlook.OlDefaultFolders.olFolderCalendar).GetStorage(
            "IPM.Configuration.WorkHours",
            Outlook.OlStorageIdentifierType.olIdentifyByMessageClass);
        Outlook.PropertyAccessor pa = storage.PropertyAccessor;
        // PropertyAccessor will return a byte array for this property
        byte[] rawXmlBytes = (byte[])pa.GetProperty(
            "http://schemas.microsoft.com/mapi/proptag/0x7C080102");
        // Use Encoding to convert the array to a string
        return System.Text.Encoding.ASCII.GetString(rawXmlBytes);
    }
    catch
    {
        return string.Empty;
    }
}

Other resources

Show:
© 2014 Microsoft