Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve task specific to user from outlook using c#

I'm using the below code to fetch tasks from 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;
        }
    }

It works fine and I'm getting a result. But suppose I have 2 Users in the Outlook data. How do you retrieve tasks specific to a particular user?

like image 290
iJade Avatar asked Jan 09 '13 15:01

iJade


1 Answers

  1. Bind Using = using Outlook = Microsoft.Office.Interop.Outlook;
  2. Create the List = public static List<Outlook.TaskItem> Aufgaben = new List<Outlook.TaskItem>();
  3. Take my code

         Outlook.MAPIFolder task = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
        foreach (Outlook.TaskItem task2 in task.Items)
        {
            //MessageBox.Show(task2.ConversationTopic);
            Aufgaben.Add(task2);
        }
    
  4. Be happy :D
like image 96
Hobelschlunze Avatar answered Sep 28 '22 06:09

Hobelschlunze