[英]How to find Achieve folders in Outlook without knowing the file path using C#
I am building an internal VSTO Outlook add-in and I need to scan all e-mails for certain numbers.我正在构建一个内部 VSTO Outlook 加载项,我需要扫描所有电子邮件中的某些数字。 I have been successful in scanning all mails on the Exchange Server, but I am having problems with the local Achive folders.我已成功扫描 Exchange Server 上的所有邮件,但本地 Achive 文件夹出现问题。
I have tried to look for many hours for a solution, but with no luck.我试图寻找解决方案很多小时,但没有运气。 All examples rely on the folder being named "Archive" or another known name that can then be hardcoded, which results in solutions like this:所有示例都依赖于名为“存档”的文件夹或其他可以硬编码的已知名称,这会产生如下解决方案:
private static _NameSpace ns = myApp.GetNamespace("MAPI");
Outlook.Folder archiveFolder = ns.Folders["Archive"] as Outlook.Folder;
How the structure might look like结构可能是什么样子
This above link shows the structure i will likely encounter among my coworkers.上面的链接显示了我可能会在我的同事中遇到的结构。 (With MANY more folders) (有更多文件夹)
I am looking for a solution that will find ALL these folders and their content OR the root folder path.我正在寻找能够找到所有这些文件夹及其内容或根文件夹路径的解决方案。 I have a method that can find all the subfolders, which i can post if needed.我有一种方法可以找到所有子文件夹,如果需要我可以发布。
I hope someone can help me:)我希望有一个人可以帮助我:)
It seems you just need to iterate over all stores in the profile by using the Stores property of the Namespace
class which returns a Stores
collection object that represents all the Store
objects in the current profile.您似乎只需要使用Namespace
class 的Stores属性来遍历配置文件中的所有商店,该属性返回代表当前配置文件中所有Store
对象的Stores
集合 object。 You can use the Stores
and Store
objects to enumerate all folders and search folders on all stores in the current session.您可以使用Stores
和Store
对象枚举所有文件夹并搜索当前 session 中所有商店上的文件夹。
Sub EnumerateFoldersInStores()
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oRoot As Outlook.Folder
On Error Resume Next
Set colStores = Application.Session.Stores
For Each oStore In colStores
Set oRoot = oStore.GetRootFolder
Debug.Print (oRoot.FolderPath)
EnumerateFolders oRoot
Next
End Sub
Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder)
Dim folders As Outlook.folders
Dim Folder As Outlook.Folder
Dim foldercount As Integer
On Error Resume Next
Set folders = oFolder.folders
foldercount = folders.Count
'Check if there are any folders below oFolder
If foldercount Then
For Each Folder In folders
Debug.Print (Folder.FolderPath)
EnumerateFolders Folder
Next
End If
End Sub
Read more about that in the Working with Outlook Accounts, Stores, Folders and Items article.在使用 Outlook 帐户、商店、文件夹和项目文章中阅读有关此内容的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.