共用方式為


取得資料夾的預設訊息類別

此範例示範如何使用 DefaultMessageClass 屬性來取得資料夾的預設訊息類別。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

若要取得資料夾的預設訊息類別,請使用MAPIFolder物件的DefaultMessageClass屬性。 例如,具有 IPM DefaultMessageClassFolder 物件。Contact 表示它代表 Contact 資料夾。 不過,如果資料夾具有自定義表單或取代表單做為預設表單,您必須使用 PropertyAccessor 物件來判斷預設表單的訊息類別。 DefaultMessageClass 屬性不會傳回資料夾之預設表單的訊息類別。

在下列程式代碼範例中,GetDefaultMessageClass 程式會使用 PropertyAccessor 來判斷資料夾的預設形式。 如果找不到 PR_DEF_POST_MSGCLASS (PidTagDefaultPostMessageClass) 的文件夾屬性,而且 Outlook 引發錯誤,請嘗試...catch 區塊會傳回 Folder的 DefaultMessageClass 屬性。

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 using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private string GetDefaultMessageClass(Outlook.Folder folder)
{
    if (folder == null)
        throw new ArgumentNullException();
    try
    {
        const string PR_DEF_POST_MSGCLASS =
            @"http://schemas.microsoft.com/mapi/proptag/0x36E5001E";
        string messageClass =
            folder.PropertyAccessor.GetProperty(
            PR_DEF_POST_MSGCLASS).ToString();
        return messageClass;
    }
    catch
    {
        return folder.DefaultMessageClass;
    }
}

另請參閱