使用c#从outlook中检索特定于用户的任务

本文关键字:用户 任务 于用户 outlook 检索 使用 | 更新日期: 2023-09-27 17:51:15

我使用下面的代码从Outlook 2007获取任务。

    public class c_tasks : IDisposable
    {
        private Microsoft.Office.Interop.Outlook.Application objOutlook = null;
        private Microsoft.Office.Interop.Outlook.NameSpace objNamespace = null;
        private Microsoft.Office.Interop.Outlook.MAPIFolder objFolder = null;
        private string strType; // this is type "Tasks"
        private int iItemCounter;
        public c_tasks()
        {
            objOutlook = new Microsoft.Office.Interop.Outlook.ApplicationClass();
            objNamespace = objOutlook.GetNamespace("MAPI");
            strType = "Tasks";
        }
        public void Dispose()
        {
            if (objOutlook != null) objOutlook.Quit();
        }
        public void iGetAllTaskItems()
        {
            int iReturn = 0;
            Microsoft.Office.Interop.Outlook.TaskItem item;
            try
            {
                objFolder = objNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderTasks);
                item = (Microsoft.Office.Interop.Outlook.TaskItem)objFolder.Items[1];
                for (int ii = 2; ii <= objFolder.Items.Count; ii++)
                {
                    string sub = item.Subject;
                    string own = item.Owner;
                }
            }
            catch (System.Exception e)
            {
            }
            return iReturn;
        }
    }

它工作得很好,我得到一个结果。但假设我在Outlook数据中有2 Users。如何检索特定于特定用户的任务?

使用c#从outlook中检索特定于用户的任务

  1. Bind Using = using Outlook = Microsoft.Office.Interop.Outlook;
  2. 创建列表= public static List<Outlook.TaskItem> Aufgaben = new List<Outlook.TaskItem>();
  3. 取我的代码

         Outlook.MAPIFolder task = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
        foreach (Outlook.TaskItem task2 in task.Items)
        {
            //MessageBox.Show(task2.ConversationTopic);
            Aufgaben.Add(task2);
        }
    
  4. 开心点:D

您的程序将在某些用户的凭据下运行。当您调用GetDefaultFolder时,它会检索该用户的任务。

为了检索另一个用户的任务,您必须调用GetSharedDefaultFolder,并且当前用户必须具有打开该共享文件夹的权限。注意GetSharedDefaultFolder链接的comments部分,有一些特殊的文件夹你不能用那个方法访问。