Outlook.Store.GetDefaultFolder Outlook is creating strange folders in a new .pst file

Add-in Express™ Support Service
That's what is more important than anything else

Outlook.Store.GetDefaultFolder Outlook is creating strange folders in a new .pst file
When used in a new Store(new .pst File without an account) the method 'GetDefaultFolder' creates stranger folders 
Desenvolvimento Fácil




Posts: 9
Joined: 2015-08-12
After creating a new .pst file only 2 folders are created by default with the new Outlook.Store(.pst).

Example 1:

User added an image

After you close Outlook and reopen it, several folders are created. Some are standard folders, such as Recycle Bin, RSSFeed, and more. But some are strange and have strange names (with strange characters).

Example 2:

User added an image

When I was debugging the code of my COM Addin I have identified that in Addin's 'Startup' event, there is a code that checks the default folders of the Outlook.Store.

The 'GetDefaultFolder' method of the Outlook.Store object is used. This method is recommended by Microsoft to identify the default folders of an Outlook.Store. And also recommended by Add-in express in this article Addin express - Working with Outlook Special Folders

Soo this is the right way.

When this method is executed, depending on the parameter, it creates the folder in Outlook.Store. I created a simple COM Addin to exemplify:

I did this:

  private StringBuilder sb = new StringBuilder("##Log##");

        //Startup
        Outlook.NameSpace ns = OutlookApp.Session;
        Outlook.Store lastStore = ns.Stores[1];//Just to get the new Store

        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderCalendar);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderConflicts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderContacts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderDeletedItems);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderDrafts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderInbox);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderJournal);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderJunk);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderLocalFailures);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderManagedEmail);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderNotes);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderOutbox);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderRssFeeds);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderSentMail);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderServerFailures);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderSuggestedContacts);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderSyncIssues);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderTasks);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olFolderToDo);
        GetDefaultFolder(lastStore, Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);

        System.Diagnostics.Debug.Write(sb.ToString());

        private void GetDefaultFolder(Outlook.Store newStore, Outlook.OlDefaultFolders olFolderKind)
    {
        Outlook.MAPIFolder rootFolder = null;

        rootFolder = newStore.GetRootFolder();
        sb.AppendLine($"qtd: {rootFolder.Folders.Count}");

        try
        {
            sb.AppendLine($"Folder kind: {olFolderKind.ToString()}");
            newStore.GetDefaultFolder(olFolderKind);
        }
        catch
        {
        }
        finally
        {
            sb.AppendLine($"qtd: {rootFolder.Folders.Count}");
            sb.AppendLine();
            sb.AppendLine();

            if (rootFolder != null)
                Marshal.ReleaseComObject(rootFolder);
        }
    }


I load the new .pst file (Outlook.Store) and fetch all default folders. But in a few cases new Folders are added.

The log of this code is:
qtd: 1 Folder kind: olFolderCalendar qtd: 2

qtd: 2 Folder kind: olFolderConflicts qtd: 2

qtd: 2 Folder kind: olFolderContacts qtd: 3

qtd: 3 Folder kind: olFolderDeletedItems qtd: 3

qtd: 3 Folder kind: olFolderDrafts qtd: 4

qtd: 4 Folder kind: olFolderInbox qtd: 4

qtd: 4 Folder kind: olFolderJournal qtd: 5

qtd: 5 Folder kind: olFolderJunk qtd: 6

qtd: 6 Folder kind: olFolderLocalFailures qtd: 6

qtd: 6 Folder kind: olFolderManagedEmail qtd: 6

qtd: 6 Folder kind: olFolderNotes qtd: 7

qtd: 7 Folder kind: olFolderOutbox qtd: 8

qtd: 8 Folder kind: olFolderRssFeeds qtd: 9

qtd: 9 Folder kind: olFolderSentMail qtd: 9

qtd: 9 Folder kind: olFolderServerFailures qtd: 9

qtd: 9 Folder kind: olFolderSuggestedContacts qtd: 9

qtd: 9 Folder kind: olFolderSyncIssues qtd: 9

qtd: 9 Folder kind: olFolderTasks qtd: 10

qtd: 10 Folder kind: olFolderToDo qtd: 10

qtd: 10 Folder kind: olPublicFoldersAllPublicFolders qtd: 10

//-------------------------------------
Questions:
What is this strange folder created by Outlook? Why is the Outlook.Store.GetDefaultFolder method creating folders? Is there another method that can be used that returns the same information as the GetDefaultFolder but DOES NOT create folders?

I created an example Addin:
Example Addin


PS.:
1 - Sorry about my bad english;
2 - This is killing me;
Posted 09 May, 2017 08:58:19 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello,

Why is the Outlook.Store.GetDefaultFolder method creating folders?


It doesn't. I suggest that you turn all other COM add-ins off.

Your English is perfectly okay with me.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 May, 2017 09:58:20 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Forgot to mention: your add-in doesn't create those folders. So, some other add-in should be involved. Or, there's a VBA macro run at some point.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 May, 2017 10:00:04 Top
Desenvolvimento Fácil




Posts: 9
Joined: 2015-08-12
Hi Andrei, Thank you by your answer.

I've removed all addins in my Outlook except my example COM add-in. And the unique code that are in that COM add-in is creating folders. All code are in the Startup event.

To simulate yout can download my example COM add-in:
http://apoio.facil.com.br/files/docsite/myaddin11.zip

1 - Open MS Outlook
2 - File
3 - Account Settings -> Data Files -> Add

I created a new .pst file with no account associated.

By default, Outlook creates only 2 folders.

Than you can close the Outlook and open again(Just to fire the Startup method of my example com addin).

Than you can check the folders of this new Store
Posted 10 May, 2017 13:33:18 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello,

I can't reproduce the issue using your add-in.

Before you start Outlook for the second time, make sure you have no OUTLOOK.EXE running in processes.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 11 May, 2017 05:50:14 Top