6
剛開始在Exchange 2010上使用Exchange Webservices 1.1時,我無法找到有關如何找到特定文件夾的示例,如果不存在,請創建它。這是如何完成的?如何查找收件箱中是否存在文件夾並創建該文件夾(如果不存在)
剛開始在Exchange 2010上使用Exchange Webservices 1.1時,我無法找到有關如何找到特定文件夾的示例,如果不存在,請創建它。這是如何完成的?如何查找收件箱中是否存在文件夾並創建該文件夾(如果不存在)
在網絡上擺弄和研究了幾天後,嗯,我想通了:
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使用== oparator所以基本上你不必做你自己的'if(folder.DisplayName.ToUpper()==「ERROR」)' – grapkulec