我正在尝试检索用户创建的所有自定义文件夹的列表,以便我可以执行全局高级搜索。我只想要包含其中包含MailItems对象的自定义文件夹,因此我想从列表中排除几个文件夹(例如RSS源,快速步骤设置,建议的联系人),这是Outlook商店中的标准。
首先,这个问题与下面提到的问题非常相似,但所选答案并未涉及自定义文件夹 - 只是所有文件夹。
有人知道如何退出一个只包含mailitem对象的自定义文件夹列表吗?我创建了一个相当大的if块来过滤掉不需要的文件夹,但我需要一个更通用的方法,因为这个将部署在用户计算机上,谁知道人们对他们的Outlook文件夹做了什么?
if (
// remove specific search folders from cope
subfolder.Name == "Quick Step Settings" || subfolder.Name == "News Feed" || subfolder.Name == "Conversation History" || subfolder.Name == "Conversation Action Settings" ||
// remove unwanted default folders from returning expiring items
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderConflicts).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJournal).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderRssFeeds).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSuggestedContacts).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSyncIssues).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderServerFailures).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderLocalFailures).FolderPath ||
subfolder.FolderPath == Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks).FolderPath ||
// eliminate certain custom folders with unwanted default types
subfolder.DefaultItemType == Outlook.OlItemType.olContactItem || subfolder.DefaultItemType == Outlook.OlItemType.olJournalItem
|| subfolder.DefaultItemType == Outlook.OlItemType.olAppointmentItem || subfolder.DefaultItemType == Outlook.OlItemType.olDistributionListItem
|| subfolder.DefaultItemType == Outlook.OlItemType.olDistributionListItem
)
{
addFolder = false;
}
答案 0 :(得分:0)
您需要以Namespace.Folders开头递归遍历所有文件夹。对于每个文件夹,请检查DefaultItemType属性。如果要排除默认邮件文件夹(例如收件箱和已发送邮件),请将文件夹的条目与从GetDefaultFolder检索到的默认文件夹的条目ID进行比较。