Directory 如何查找收件箱中是否存在文件夹,如果不存在则创建文件夹
刚刚开始在Exchange 2010上使用Exchange Webservices 1.1。我找不到有关如何查找特定文件夹的示例,如果不存在,请创建它。这是怎么做到的?经过几天的网上摆弄和研究,我发现:Directory 如何查找收件箱中是否存在文件夹,如果不存在则创建文件夹,directory,exchangewebservices,Directory,Exchangewebservices,刚刚开始在Exchange 2010上使用Exchange Webservices 1.1。我找不到有关如何查找特定文件夹的示例,如果不存在,请创建它。这是怎么做到的?经过几天的网上摆弄和研究,我发现: FolderView fv = new FolderView(10); var findFoldersResults = service.FindFolders( WellKnownFolderName.Inbox, new SearchFilter.SearchFilterC
FolderView fv = new FolderView(10);
var findFoldersResults = service.FindFolders(
WellKnownFolderName.Inbox,
new SearchFilter.SearchFilterCollection(
LogicalOperator.Or,
new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, "ERROR"), new SearchFilter.ContainsSubstring(FolderSchema.DisplayName, "ARCHIVE")),
fv);
foreach (var folder in findFoldersResults)
{
if (folder is Folder)
{
if (folder.DisplayName.ToUpper() == "ARCHIVE")
{
archiveFolderID = folder.Id;
}
else if (folder.DisplayName.ToUpper() == "ERROR")
{
errorFolderID = folder.Id;
}
}
}
//if archive folder not found create and assign the variable to the folderID
if (archiveFolderID == null)
{
Folder folder = new Folder(service);
folder.DisplayName = "ARCHIVE";
folder.Save(WellKnownFolderName.Inbox);
archiveFolderID = folder.Id;
}
//if error folder not found create and assign the variable to the folderID
if (errorFolderID == null)
{
Folder folder = new Folder(service);
folder.DisplayName = "ERROR";
folder.Save(WellKnownFolderName.Inbox);
errorFolderID = folder.Id;
}
可能您也可以使用SearchFilter.IsEqualTo,因为ContainsSubstring将返回名为“NoERRORS”或“ERRORSNotAllowed”的文件夹,而IsEqualTo使用==Operator,因此基本上您不必自己执行“if(folder.DisplayName.ToUpper()=”ERROR“)”