Get information about stores in a profile

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

Example

Note

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

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

See also