我如何使用EWS Web服务在Outlook中检查文件夹和子文件夹是否存在& C#
我是C#开发的新手。 我正在尝试使用Exchange Web服务在Outlook Mailbox中检查并创建一个文件夹/子文件夹。
文件夹结构
- main_folder
- sub folder-1
- sub文件夹-2
- sub文件夹3
实现,
public void checkFolderExistOrNot( String folder_name)
{
FolderView fv = new FolderView(100);
var findFoldersResults = exchangeService.FindFolders(
WellKnownFolderName.Inbox,
new SearchFilter.SearchFilterCollection(
LogicalOperator.Or,
new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, folder_name)),
fv);
foreach (var folder in findFoldersResults)
{
if (folder is Folder)
{
if (folder.DisplayName == folder_name)
{
archiveFolderID = folder.Id;
}
}
}
//if archive folder not found create and assign the variable to the folderID
if (archiveFolderID == null)
{
Folder folder = new Folder(exchangeService);
folder.DisplayName = folder_name;
folder.Save(WellKnownFolderName.Inbox);
archiveFolderID = folder.Id;
}
}
checkFolderExistOrNot(MAIN_folder)
checkFolderExistOrNot(MAIN_folder.Sub Folder-1)
checkFolderExistOrNot(MAIN_folder.Sub Folder-2)
checkFolderExistOrNot(MAIN_folder.Sub Folder-3)
但这仅在收件箱下创建主文件夹。如果有人可以帮助我确定我的实施中缺少的内容,这将不胜感激。
提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
判断文件夹是否存在的唯一方法是通过搜索搜索它,因为您没有指定folderview中的遍历,它将始终很浅。如果您在其中指定了深度遍历,
则应该能够找到要在ON上创建新子文件夹的父文件夹。只要您没有任何名称冲突的文件夹级别,您的逻辑就可以正常工作。否则我要做的就是 Exchange Web Service for A for A用户创建的文件夹或
The only way to tell if a folder exists is to search for it with your search because you don't specify the traversal in the Folderview it will always be shallow. If you specify a deep traversal in
You should then be able to find the parent folder you want to create a new subfolder on. Your logic should work okay as long as you don't have any name clashes a different folder levels. Otherwise what I do is this Exchange Web Service FolderId for a folder created by user or Get to an Exchange folder by path using EWS
您是否给出了 Microsoft Graph 看起来?
您基本上可以将其用于Microsoft 365中的任何东西。您也可以实现自己的目标。
您将需要创建一个
GraphServiceClient
,并且可以进行以下操作以检查文件夹是否存在:一旦有父母文件夹,您就可以获取它的ID,并且一旦您知道可以搜索它儿童文件夹:
如果
childmailfolder.count> 0
然后存在文件夹,如果不是,则创建了子文件夹:Have you given Microsoft Graph a look?
You can basically use it for anything in Microsoft 365. With you you can also achieve your goal.
You will need to create a
GraphServiceClient
and with it you can do the following to check if a folder exists:Once you have the parent folder you can get it's ID and once you know that you can search it for child folders:
If the
childMailFolder.Count > 0
then the folder exists, if not you create the child folder: