简体   繁体   English

如何在不知道文件路径的情况下使用 C# 在 Outlook 中找到实现文件夹

[英]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.您可以使用StoresStore对象枚举所有文件夹并搜索当前 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.

相关问题 如何在不实际知道C#Windows应用程序窗体目录中的完整路径文件的情况下自动查找文件 - How to find a file automatically without actually knowing the full path file in directory in C# windows application Form 使用xpath查找节点而不知道c#中的属性名称 - Using xpath to find a node without knowing attributes name in c# 如何在不知道任何使用C#的机器名称的情况下找到LAN上所有共享的名称? - How can I find the names of all shares on a LAN without knowing any machine names using C#? 如何使用 C# 在 Outlook 中为多个文件夹添加 ItemAddEventHandler? - How to add ItemAddEventHandler for multiple folders in outlook using C#? 如何使用 C# 更新所有 Outlook(2003) 文件夹 - how to Update All Outlook(2003) Folders using C# C#:在不知道密钥在哪里的情况下找到密钥 - C#: Find a key without knowing where it is 搜索文件并删除,不知道路径C# - Search for file and delete it, not knowing the path C# 如何通过C#中的WMI根据不同的扩展名查找C驱动器的文件和子文件夹中的文件路径列表 - How to find list of file path in files and in sub folders of C Drive based on different extension through WMI in C# 在不知道确切路径的情况下使用C#启动外部程序 - Launching external programs in C# without knowing the exact path 如何在不将Outlook与C#结合使用的情况下发送约会重复 - How to send an appointment recurrence without using Outlook with C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM