Outlook AddIn用于过滤收件人

时间:2017-10-17 17:28:38

标签: c# outlook vsto

我想在C#中构建一个Outlook AddIn,它在日历功能区中有一个按钮,用户单击该按钮可以与其中一个员工建立新会议。我们希望用户(经理)能够从仅有自己员工的筛选列表中选择员工,而不必搜索整个目录。 这样做的最佳方式是什么?

附录: 我做了一些搜索,我发现了一种潜在的过滤方法。

我知道" SelectNamesDialog"函数将为我提供一个地址簿对话框:

Outlook.SelectNamesDialog snd = Application.Session.GetSelectNamesDialog();

我想将它与我找到的一段代码结合起来。我对其进行了修改,以返回所有经理的直接报告(经理下的员工)的姓名。

我认为我走在正确的轨道上,但我不确定接下来该做什么。我现在如何允许用户通过GetSelectNamesDialog选择其中一个名称?如果您的答案是伪造的,那就没关系了。

// source: "How to: Get Information About Direct Reports of the Current User's Manager" 
// https://msdn.microsoft.com/en-us/library/ff184617.aspx
        private List<string> GetManagerDirectReports()
        {
            List<string> AddressNames = new List<string>();

            Outlook.AddressEntry currentUser = Globals.ThisAddIn.Application.Session.CurrentUser.AddressEntry;
            if (currentUser.Type == "EX")
            {
                Outlook.ExchangeUser manager = currentUser.GetExchangeUser().GetExchangeUserManager();
                if (manager != null)
                {
                    Outlook.AddressEntries addrEntries = manager.GetDirectReports();
                    if (addrEntries != null)
                    {
                        foreach (Outlook.AddressEntry addrEntry in addrEntries)
                        {
                            //System.Windows.Forms.MessageBox.Show(addrEntry.Name);
                            AddressNames.Add(addrEntry.Name);
                        }
                    }
                }
            }
            return AddressNames;
        }

2 个答案:

答案 0 :(得分:0)

地址簿不允许您将列表限制为某些用户的子集,因此您需要提供自己的窗口,提示用户从预先过滤的列表中进行选择。

答案 1 :(得分:0)

我现在似乎能够发布自己的问题的答案。

我在表单区域中添加了一个下拉列表,并添加了以下代码以使用经理的直接报告的名称填充该下拉列表:

// Get Outlook list of employees who report to manager, using Exchange data.
List<string> mgrAddressNames = GetManagerDirectReports();

if (mgrAddressNames.Count >= 1)
{
   try
   {
    // System.Windows.Forms.BindingSource bindingSource1;
    // Create a Binding Source to the ComboBox to make values in ComboBox match the results of the list of direct reports.
    System.Windows.Forms.BindingSource bindingSource1 = new System.Windows.Forms.BindingSource();
    bindingSource1.DataSource = mgrAddressNames;
    EmployeeInvited.DisplayMember = "Value";
    EmployeeInvited.ValueMember = "Key";
    EmployeeInvited.DataSource = bindingSource1.DataSource;

    bindingSource1.Dispose();

(etc)