// Uses recursion to enumerate Outlook subfolders. private void EnumerateFolders(Microsoft.Office.Interop.Outlook.MAPIFolder folder) { //cmbOutlookFolders.Items.Add(folder.Name); Microsoft.Office.Interop.Outlook.Folders childFolders = folder.Folders; if (childFolders.Count > 0) { foreach (Microsoft.Office.Interop.Outlook.MAPIFolder childFolder in childFolders) { try { // Write the folder path. Debug.WriteLine(childFolder.FolderPath); KeyValuePair <string, string> folderItem = new KeyValuePair <string, string>(childFolder.EntryID, childFolder.Name);// { } cmbOutlookFolders.Items.Add(folderItem); // Call EnumerateFolders using childFolder. EnumerateFolders(childFolder); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } }
static void EnumerateFolders(Microsoft.Office.Interop.Outlook.Folder folder, string pathToSaveFile) { Microsoft.Office.Interop.Outlook.Folders childFolders = folder.Folders; if (childFolders.Count > 0) { foreach (Microsoft.Office.Interop.Outlook.Folder childFolder in childFolders) { // We only want Inbox folders - ignore Contacts and others if (childFolder.FolderPath.Contains("Inbox")) { MessageBox.Show(childFolder.FolderPath); // Call EnumerateFolders using childFolder, to see if there are any sub-folders within this one EnumerateFolders(childFolder, pathToSaveFile); } } } MessageBox.Show("Checking in " + folder.FolderPath); IterateMessages(folder, pathToSaveFile); }
internal static void LoadSettings(out string gmailUsername, out string syncProfile, out string syncContactsFolder, out string syncAppointmentsFolder) { Microsoft.Win32.RegistryKey regKeyAppRoot = LoadSettings(out gmailUsername, out syncProfile); syncContactsFolder = ""; syncAppointmentsFolder = ""; AppointmentsSynchronizer.SyncAppointmentsGoogleFolder = ""; //First, check if there is a folder called GCSMTestContacts available, if yes, use them ArrayList outlookContactFolders = new ArrayList(); ArrayList outlookNoteFolders = new ArrayList(); ArrayList outlookAppointmentFolders = new ArrayList(); Microsoft.Office.Interop.Outlook.Folders folders = Synchronizer.OutlookNameSpace.Folders; foreach (Microsoft.Office.Interop.Outlook.Folder folder in folders) { try { SettingsForm.GetOutlookMAPIFolders(outlookContactFolders, outlookAppointmentFolders, folder); } catch (Exception e) { Logger.Log("Error getting available Outlook folders: " + e.Message, EventType.Warning); } } foreach (OutlookFolder folder in outlookContactFolders) { if (folder.FolderName.ToUpper().Contains("GCSMTestContacts".ToUpper())) { Logger.Log("Uses Test folder: " + folder.DisplayName, EventType.Information); syncContactsFolder = folder.FolderID; break; } } foreach (OutlookFolder folder in outlookAppointmentFolders) { if (folder.FolderName.ToUpper().Contains("GCSMTestAppointments".ToUpper())) { Logger.Log("Uses Test folder: " + folder.DisplayName, EventType.Information); syncAppointmentsFolder = folder.FolderID; break; } } if (string.IsNullOrEmpty(syncContactsFolder)) { if (regKeyAppRoot.GetValue("SyncContactsFolder") != null) { syncContactsFolder = regKeyAppRoot.GetValue("SyncContactsFolder") as string; } } if (string.IsNullOrEmpty(syncAppointmentsFolder)) { if (regKeyAppRoot.GetValue("SyncAppointmentsFolder") != null) { syncAppointmentsFolder = regKeyAppRoot.GetValue("SyncAppointmentsFolder") as string; } } if (string.IsNullOrEmpty(AppointmentsSynchronizer.SyncAppointmentsGoogleFolder)) { if (regKeyAppRoot.GetValue("SyncAppointmentsGoogleFolder") != null) { AppointmentsSynchronizer.SyncAppointmentsGoogleFolder = regKeyAppRoot.GetValue("SyncAppointmentsGoogeFolder") as string; } } }