共用方式為


存取儲存為資料夾中隱藏訊息的解決方案特定資料

此範例示範如何使用 StorageItem 物件來擷取儲存為資料夾中特定訊息類別之隱藏訊息的數據。

範例

StorageItem 物件通常用來隱藏無法以程式設計方式顯示的解決方案特定數據。 在 Exchange 環境中, StorageItem 物件可用來漫遊解決方案設定,並確保這些設定可在在線和離線使用。 您可以將自定義訊息類別指派給 StorageItem 物件,或依主體識別物件。

下列程式代碼範例會擷取儲存為 Calendar 資料夾中隱藏訊息的 XML 數據,其訊息類別等於 IPM。Configuration.WorkHours。

PropertyAccessor 物件會將 XML 傳回為包含位元組數據流的物件,而不是 XML 的字串表示。 程式代碼範例會使用 System.Text.Encoding.Ascii.GetString 將位元組數據流轉換成字串。

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#.

Imports Outlook = Microsoft.Office.Interop.Outlook
using Outlook = Microsoft.Office.Interop.Outlook;
Private Function GetWorkHoursXML() As String
    Try
        Dim storage As Outlook.StorageItem = _
            Application.Session.GetDefaultFolder( _
            Outlook.OlDefaultFolders.olFolderCalendar).GetStorage( _
            "IPM.Configuration.WorkHours", _
            Outlook.OlStorageIdentifierType.olIdentifyByMessageClass)
        Dim pa As Outlook.PropertyAccessor = storage.PropertyAccessor
        ' PropertyAccessor will return a byte array for this property
        Dim rawXmlBytes As Byte() = CType(pa.GetProperty( _
            "http://schemas.microsoft.com/mapi/proptag/0x7C080102"), _
            Byte())
        ' Use Encoding to convert the array to a string
        Return System.Text.Encoding.ASCII.GetString(rawXmlBytes)
    Catch
        Return String.Empty
    End Try
End Function
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;
    }
}

另請參閱