The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

How to: Add or Remove a Store

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This example shows how to add and remove a store in a given profile.

This code sample shows how to add and remove a store in a specified profile, by calling the AddStoreEx method and the RemoveStore method respectively on the NameSpace object.

In Outlook, you can add or remove a PST store only programmatically. The following code sample adds a Unicode store and places the .pst file in the default location for user .pst files: Documents and Settings\<UserName>\Local Settings\Application Data\Microsoft\Outlook. The code sample uses Environment.SpecialFolder.LocalApplicationData to retrieve the path to the Application Data folder under the Local Settings folder. Once the store has been added, the code sample removes the store. Because the RemoveStore method requires a Folder object to remove the Store object, it enumerates the Stores collection to find the Store object that has just been added based on the FilePath property of the Store object.

RemoveStore only removes the store from the current profile. It does not delete the .pst file from the file system.

If you use Microsoft Visual Studio to test this code sample, you must first add a reference to the Microsoft Outlook 12.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The Imports or using statements must not occur right before the functions in the Code section but must be added before the public Class declaration. The following lines of code show how to do the import and assignment in Visual Basic and in C#:

using Outlook = Microsoft.Office.Interop.Outlook;
private void CreateUnicodePST()
    string path = Environment.GetFolderPath(
        + @"\Microsoft\Outlook\MyUnicodeStore.pst";
            path, Outlook.OlStoreType.olStoreUnicode);
        Outlook.Stores stores = Application.Session.Stores;
        foreach (Outlook.Store store in stores)
            if (store.FilePath == path)
               Outlook.Folder folder =
                    store.GetRootFolder() as Outlook.Folder;
               // Remove the store
    catch (Exception ex)