Outlook对话历史

时间:2012-05-08 08:44:08

标签: c# outlook office-interop

我正在研究创建一个outlook插件,我可以从Conversation History文件夹中选择一个对话,然后单击一个将其保存到文件夹的按钮。有没有人知道如何通过C#选择对话历史记录文件夹和运行搜索以及选择对话。

1 个答案:

答案 0 :(得分:0)

    public static List<Outlook.MAPIFolder> GetFolders()
    {

        List<Outlook.MAPIFolder> _list = new List<Outlook.MAPIFolder>();

        Outlook.MAPIFolder root = OutlookApplication.Session.DefaultStore.GetRootFolder();


        foreach (Outlook.MAPIFolder folder in root.Folders)
        {
            _list.Add(folder);
        }

        return _list;
    }

    public static Outlook.MAPIFolder GetFolderByEntryId(string entryId)
    {
        List<Outlook.MAPIFolder> folders = GetFolders();
        return folders.Where(x => x.EntryID == entryId).FirstOrDefault();
    }

    public static Outlook.MAPIFolder GetFolderByName(string folderName)
    {
        List<Outlook.MAPIFolder> folders = GetFolders();
        return folders.Where(x => x.Name == folderName).FirstOrDefault();
    }

    public static List<Outlook.MailItem> GetSelectedItem()
    {
        List<Outlook.MailItem> _list = new List<Outlook.MailItem>();

        Outlook.Selection outlookSelection = OutlookApplication.ActiveExplorer().Selection;

        for (int i = 1; i < outlookSelection.Count; i++)
        {
            Outlook.MailItem mailItem = (Outlook.MailItem)outlookSelection[i];

            _list.Add(mailItem);
        }

        return _list;
    }

    public static List<Outlook.MailItem> GetMailItems(string FolderName)
    {
        List<Outlook.MailItem> _list = new List<Outlook.MailItem>();

        Outlook.MAPIFolder theFolder = OutlookApplication.Session.GetFolderFromID(GetFolderByName(FolderName).EntryID);

        foreach (Object item in theFolder.Items)
        {
            Outlook.MailItem mailItem = (Outlook.MailItem)item;

            if (mailItem != null)
            {
                _list.Add(mailItem);
            }
        }

        return _list;

    }