How to: Get Information About Stores in a Profile

Office 2013 and later

This example shows how to get and enumerate stores in a profile.

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

You can use the Stores collection to enumerate the stores for a given profile. The Stores collection provides members that expose information about each Store object, such as when a Store object has been added or when a Store object is about to be removed in the current profile. In the following code example, EnumerateStores gets the Stores object that represents stores in the current profile, and enumerates the stores. EnumerateStores examines each Store object in the Stores collection. If the IsDataFileStore property returns true, indicating that it is a .pst or .ost store, the DisplayName and FilePath properties are written to the trace listeners in the Listeners collection.

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 void EnumerateStores()
    Outlook.Stores stores = Application.Session.Stores;
    foreach (Outlook.Store store in stores)
        if (store.IsDataFileStore == true)
            Debug.WriteLine(String.Format("Store: "
            + store.DisplayName
            + "\n" + "File Path: "
            + store.FilePath + "\n"));

Other resources