How to: 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.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

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 Microsoft Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 14.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();
        const string PR_DEF_POST_MSGCLASS =
        string messageClass =
        return messageClass;
        return folder.DefaultMessageClass;

Other Resources