I want to know if there is a better way to detect if a folder inside a store was created by the user, or if it is a default folder (created by Outlook).
I have the code below, which iterates over all the folders in a store, detecting some of the default ones.
public List<string> GetEntryIDFoldersToMonitor()
{
OlDefaultFolders[] defaultFolders = new OlDefaultFolders[]
{
OlDefaultFolders.olFolderCalendar,
OlDefaultFolders.olFolderConflicts,
OlDefaultFolders.olFolderContacts,
OlDefaultFolders.olFolderDeletedItems,
OlDefaultFolders.olFolderDrafts,
OlDefaultFolders.olFolderJournal,
OlDefaultFolders.olFolderJunk,
OlDefaultFolders.olFolderLocalFailures,
OlDefaultFolders.olFolderNotes,
OlDefaultFolders.olFolderOutbox,
OlDefaultFolders.olFolderRssFeeds,
OlDefaultFolders.olFolderSentMail,
OlDefaultFolders.olFolderServerFailures,
OlDefaultFolders.olFolderSuggestedContacts,
OlDefaultFolders.olFolderSyncIssues,
OlDefaultFolders.olFolderTasks,
OlDefaultFolders.olFolderToDo
};
Stores stores = Global.OutlookApp.Session.Stores;
MAPIFolder folder = null;
List<string> foldersToMonitor = new List<string>();
for (int i = 1; i < stores.Count; i++)
{
Store store = stores[i];
try
{
for (int j = 0; j < defaultFolders.Length; j++)
folder = store.GetDefaultFolder(defaultFolders[j]);
}
catch { continue; }
try
{
if (folder != null)
foldersToMonitor.Add(folder.EntryID);
}
finally
{
if (folder != null)
Marshal.ReleaseComObject(folder);
}
}
return foldersToMonitor;
}
I'm asking this because some of the folders take too long to load. For example, in one of our users, the default folder olServerFailures took 55 seconds to process.
Is there a better way to detect that?
There are no markers for identifying built-in and custom folders. You can get the folder by using the GetDefaultFolder(OlDefaultFolders) method which allows getting a Folder
object that represents the default folder of the requested type for the current profile or store. So then you will be able to differentiate built-in and custom folders.
If a particular folder takes too much time for retrieving any information you just need to avoid such calls.