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

iJa*_*ade 6 c# asp.net outlook office-interop

我正在使用以下代码从中获取任务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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

它工作正常,我得到一个结果.但是假设我有2 UsersOutlook数据.如何检索特定于特定用户的任务?

Rea*_*ilt 0

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

为了检索其他用户的任务,您必须调用GetSharedDefaultFolder,并且当前用户必须有权打开该共享文件夹。请注意 GetSharedDefaultFolder 链接的备注部分,有一些特殊文件夹无法使用该方法访问。