2

我一直在为自己做一个小周末项目,其中包括从 Outlook 获取我所有的 ToDo 任务,将它们放在 DataGridView 中,然后我就可以编辑和导出它们。

我遇到的唯一问题是当标记的电子邮件仍然存在时,我无法获取它们的任务特定属性,我只是看不到任何访问它们的方法。

这是我当前代码的一部分。

private void retrieveTasks()
    {

        //Clear datagrid so we won't have duplicate information
        taskList.Rows.Clear();

        //Define some properties so we can use these to retrieve the tasks
        Outlook.Application app = null;
        _NameSpace ns = null;
        Store outlookStore = null;
        Outlook.MAPIFolder taskFolder = null;
        Outlook.MAPIFolder specialFolder = null;
        TaskItem task = null;
        DateTime nonDate = new DateTime(4501, 1, 1);

        try
        {
            //Connect to Outlook via MAPI
            app = new Outlook.Application();
            ns = app.GetNamespace("MAPI");
            ns.Logon(null, null, false, false);

            /*
            outlookStore = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Store;
            taskFolder = outlookStore.GetSpecialFolder(Microsoft.Office.Interop.Outlook.OlSpecialFolders.olSpecialFolderAllTasks);
            */

            //Get the taskfolder containing the Outlook tasks
            //taskFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
            outlookStore = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox).Store;
            taskFolder = outlookStore.GetSpecialFolder(OlSpecialFolders.olSpecialFolderAllTasks);
            //Console.WriteLine(specialFolder.Items[1].Subject.ToString());

            /*for (int i = 1; i <= specialFolder.Items.Count; i++)
            {
                //task = (Outlook.TaskItem)specialFolder.Items[i];
                Console.WriteLine(specialFolder.Items[i].ToString());
            }*/

            for (int i = 1; i <= taskFolder.Items.Count; i++)
            {
                //Get task from taskfolder
                Object item = taskFolder.Items[i];
                if (item is Outlook.MailItem)
                {
                    MailItem mail = (Outlook.MailItem)item;
                    if (mail.TaskCompletedDate.Equals(nonDate))
                    {
                        string percentComplete = "";
                        string taskPrio = "";
                        if (mail.UserProperties.Find("Prio") == null)
                        {
                            taskPrio = "";
                        }
                        else
                        {
                            taskPrio = mail.UserProperties.Find("Prio").Value.ToString();
                        }

                        //mail.UserProperties.

                        if (mail.UserProperties.Find("% Complete") == null)
                        {
                            percentComplete = "";
                        }
                        else
                        {
                            percentComplete = mail.UserProperties.Find("% Complete").Value.ToString();
                        }

                        //Add the tasks details to the datagrid
                        taskList.Rows.Add(
                            i.ToString(),
                            checkForNull(mail.Subject),
                            parseDate(mail.TaskStartDate.ToString()),
                            parseDate(mail.TaskDueDate.ToString()),
                            percentComplete, "Taak voltooid",
                            //statusToFriendlyName(mail.Status.ToString()),
                            taskPrio
                        );
                    }
                }
                else if (item is Outlook.TaskItem)
                {
                    task = (Outlook.TaskItem)item;
                    Console.WriteLine(task.Subject);
                    if (task.Complete == false)
                    {
                        string taskPrio = "";

                        //Make sure custom task property is failed or set it to empty text to prevent crashes
                        if (task.UserProperties.Find("Prio") == null)
                        {
                            taskPrio = "";
                        }
                        else
                        {
                            taskPrio = task.UserProperties.Find("Prio").Value.ToString();
                        }

                        //Add the tasks details to the datagrid
                        taskList.Rows.Add(
                            i.ToString(),
                            task.Subject.ToString(),
                            parseDate(task.StartDate.ToString()),
                            parseDate(task.DueDate.ToString()),
                            task.PercentComplete.ToString(),
                            statusToFriendlyName(task.Status.ToString()),
                            taskPrio
                        );
                    }
                }


            }
        }
        catch (System.Runtime.InteropServices.COMException ex)
        {
            MessageBox.Show(ex.ToString());
        }
        finally
        {
            //Release Outlook sources
            ns = null;
            app = null;
        }
    }

所以特别是我正在寻找“%完成”属性和状态属性,以及我能够解决的所有其他问题。

如果我能让这个工作起来,我的生活会变得容易得多:)

希望在这里听到任何人的声音!

杰弗里

4

1 回答 1

2

您的意思是您需要从 MailItem 对象(而不是 TaskItem 对象)中检索特定于任务的属性吗?

使用OutlookSpy查看消息- 单击 IMessage 按钮,查看 GetProps 选项卡中的 MAPI 属性。任何属性都可以使用MailItem.PropertyAccessor.GetProperty. 要使用的 DASL 名称GetProperty由 OutlookSpy 显示(在 IMessage 窗口中选择属性,请参见 DASL 编辑框)。

于 2013-07-08T07:27:28.820 回答