所有文件夹中的Exchange Web服务(EWS)FindItems [英] Exchange Web Services (EWS) FindItems within All Folders

查看:462
本文介绍了所有文件夹中的Exchange Web服务(EWS)FindItems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码来找到所有来自用户发送这些电子邮件,然而,这仅搜索主收件箱文件夹和不检查任何子文件夹。我想搜索所有邮件项目包括所有子文件夹。



我曾尝试WellKnownFolderName.Root和WellKnownFolderName.Inbox而这些只能搜索这些文件夹,而不是子文件夹。

 私有静态无效SearchItems(字符串email)
{
ItemView控件IV =新ItemView控件(10);
FindItemsResults<项目> fiitems = _service.FindItems(WellKnownFolderName.Inbox,来自:username@example.com,IV);

的foreach(在fiitems项项)
{
Console.WriteLine(主题:\t+ item.Subject);
Console.WriteLine(接受过:\t\t+ item.DateTimeReceived.ToString(DD MMMM YYYY));
Console.WriteLine();
}

Console.WriteLine(按Enter键继续);
到Console.ReadLine();
}


解决方案

我已经发现了一些信息,在格伦的博客 http://gsexdev.blogspot.com /2011/08/using-allitems-search-folder-from.html 我已经移植了PowerShell脚本到C#,如下图所示。

 私有静态无效SearchItems()
{

ExtendedPropertyDefinition allFoldersType =新ExtendedPropertyDefinition(13825,MapiPropertyType.Integer);

FolderId rootFolderId =新FolderId(WellKnownFolderName.Root);
文件夹视图文件夹视图=新的文件夹视图(1000);
folderView.Traversal = FolderTraversal.Shallow;

SearchFilter searchFilter1 =新SearchFilter.IsEqualTo(allFoldersType,2);
SearchFilter searchFilter2 =新SearchFilter.IsEqualTo(FolderSchema.DisplayNameallitems);
SearchFilter.SearchFilterCollection searchFilterCollection =新SearchFilter.SearchFilterCollection(LogicalOperator.And);
searchFilterCollection.Add(searchFilter1);
searchFilterCollection.Add(searchFilter2);

FindFoldersResults findFoldersResults = _service.FindFolders(rootFolderId,searchFilterCollection,文件夹视图);

如果(findFoldersResults.Folders.Count大于0)
{
夹allItemsFolder = findFoldersResults.Folders [0];
Console.WriteLine(文件夹:\t+ allItemsFolder.DisplayName);

ItemView控件IV =新ItemView控件(1000);
FindItemsResults<项目> findResults = allItemsFolder.FindItems(System.Message.DateReceived:01/01 / 2011..01 / 31/2011」,IV);

的foreach(在findResults项项)
{
Console.WriteLine(主题:\t+ item.Subject);
Console.WriteLine(接受过:\t\t+ item.DateTimeReceived.ToString(DD MMMM YYYY));
Console.WriteLine(是新的:\t\t+ item.IsNew.ToString());
Console.WriteLine(有附件:\t\t+ item.HasAttachments.ToString());
Console.WriteLine();
}

}

Console.WriteLine(按Enter键继续);
到Console.ReadLine();
}


I am using the following code to find all the emails sent from a user, however this only searches the main Inbox folder and doesn't check any sub-folders. I would like to search all the mail items including any sub-folders.

I have tried the WellKnownFolderName.Root and WellKnownFolderName.Inbox and these only search those folders, not the sub-folders.

    private static void SearchItems(string email)
    {
        ItemView iv = new ItemView(10);
        FindItemsResults<Item> fiitems = _service.FindItems(WellKnownFolderName.Inbox, "from:username@example.com", iv);

        foreach (Item item in fiitems)
        {
            Console.WriteLine("Subject:\t" + item.Subject);
            Console.WriteLine("Received At:\t\t" + item.DateTimeReceived.ToString("dd MMMM yyyy"));
            Console.WriteLine();
        }

        Console.WriteLine("Press Enter to continue");
        Console.ReadLine();
    }

解决方案

I have found some information on the AllItems folder within Exchange over at Glen's blog http://gsexdev.blogspot.com/2011/08/using-allitems-search-folder-from.html I have ported the PowerShell script to C# as shown below.

    private static void SearchItems()
    {

        ExtendedPropertyDefinition allFoldersType = new ExtendedPropertyDefinition(13825, MapiPropertyType.Integer);

        FolderId rootFolderId = new FolderId(WellKnownFolderName.Root);
        FolderView folderView = new FolderView(1000);
        folderView.Traversal = FolderTraversal.Shallow;

        SearchFilter searchFilter1 = new SearchFilter.IsEqualTo(allFoldersType, "2");
        SearchFilter searchFilter2 = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "allitems");
        SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
        searchFilterCollection.Add(searchFilter1);
        searchFilterCollection.Add(searchFilter2);

        FindFoldersResults findFoldersResults = _service.FindFolders(rootFolderId, searchFilterCollection, folderView);

        if (findFoldersResults.Folders.Count > 0)
        {
            Folder allItemsFolder = findFoldersResults.Folders[0];
            Console.WriteLine("Folder:\t" + allItemsFolder.DisplayName);

            ItemView iv = new ItemView(1000);
            FindItemsResults<Item> findResults = allItemsFolder.FindItems("System.Message.DateReceived:01/01/2011..01/31/2011", iv);

            foreach (Item item in findResults)
            {
                Console.WriteLine("Subject:\t" + item.Subject);
                Console.WriteLine("Received At:\t\t" + item.DateTimeReceived.ToString("dd MMMM yyyy"));
                Console.WriteLine("Is New:\t\t" + item.IsNew.ToString());
                Console.WriteLine("Has Attachments:\t\t" + item.HasAttachments.ToString());
                Console.WriteLine();
            }

        }

        Console.WriteLine("Press Enter to continue");
        Console.ReadLine();
    }

这篇关于所有文件夹中的Exchange Web服务(EWS)FindItems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆