Get the default message class of a folder

This example shows how to use the DefaultMessageClass property to obtain the default message class of a folder.

Example

Note

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.

To obtain the default message class for a folder, use the DefaultMessageClass property of the MAPIFolder object. For example, a Folder object that has a DefaultMessageClass of IPM.Contact means that it represents a Contact folder. However, if the folder has a custom form or a replacement form as a default form, you must use the PropertyAccessor object to determine the message class of the default form. The DefaultMessageClass property does not return the message class of the default form for the folder.

In the following code example, the GetDefaultMessageClass procedure uses the PropertyAccessor to determine the default form of a folder. If the folder property PR_DEF_POST_MSGCLASS (PidTagDefaultPostMessageClass) is not found and Outlook raises an error, the try…catch block returns the DefaultMessageClass property for the Folder.

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;
    }
}

See also