This project has moved. For the latest updates, please go here.

Tasks support (preview)

Coordinator
Mar 12, 2015 at 6:55 PM
This thread is to redirect all issues/requests of Tasks and have them in a centralized place. :-)
Mar 22, 2015 at 10:35 PM
Hi Gamosoft,

Thank you for adding task support to your great outlook add-in. I had a small issue when deleting a task from my Hotmail account. When I start the add-in from Visual Studio Community 2013.4 I got a COM exception error:

Image_COM_Exception

The task remains visible in the task panel. A refresh (clicking on Today) don't help to remove the task from the list. After a restart of outlook the task is gone. When I don't start the add-in within visual studio I don't get an error, but the task is still visible and don't disappear after a refresh.

I only use Hotmail accounts so I don't know the behavior when deleting tasks from an outlook datafile / account on an exchange server.

I changed the code a little bit and now it is working fine for me (both with and without Visual Studio). I don't know you are able to reproduce the error I got, but I want to share my solution.

I added a try/catch in the OLTaskItem.cs:
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="item">Outlook item in the tasks folder</param>
        public OLTaskItem(object item)
        {
            try
            {
                // TODO: Priority, status, % complete
                this.ValidTaskItem = true;
                this.OriginalItem = item;
                this.Categories = new List<string>();
                if (item is Outlook.MailItem)
                {
                    Outlook.MailItem mail = item as Outlook.MailItem;
                    this.TaskType = "Mail";
                    this.TaskSubject = mail.TaskSubject;
                    this.StartDate = mail.TaskStartDate;
                    this.Reminder = mail.ReminderTime;
                    this.DueDate = mail.TaskDueDate;
                    MAPIFolder f = (MAPIFolder)mail.Parent;
                    this.FolderName = f.Name;
                    if (!String.IsNullOrEmpty(mail.Categories)) this.Categories.AddRange(mail.Categories.Split(new char[] { ',' }));
                    this.Completed = (mail.TaskCompletedDate.Year != Constants.NullYear);
                }
                else if (item is Outlook.ContactItem)
                {
                    Outlook.ContactItem contact = item as Outlook.ContactItem;
                    this.TaskType = "Contact";
                    this.TaskSubject = contact.TaskSubject;
                    this.StartDate = contact.TaskStartDate;
                    this.Reminder = contact.ReminderTime;
                    this.DueDate = contact.TaskDueDate;
                    MAPIFolder f = (MAPIFolder)contact.Parent;
                    this.FolderName = f.Name;
                    if (!String.IsNullOrEmpty(contact.Categories)) this.Categories.AddRange(contact.Categories.Split(new char[] { ',' }));
                    this.Completed = (contact.TaskCompletedDate.Year != Constants.NullYear);
                }
                else if (item is Outlook.TaskItem)
                {
                    Outlook.TaskItem task = item as Outlook.TaskItem;
                    this.TaskType = "Task";
                    this.TaskSubject = task.Subject;
                    this.StartDate = task.StartDate;
                    this.Reminder = task.ReminderTime;
                    this.DueDate = task.DueDate;
                    MAPIFolder f = (MAPIFolder)task.Parent;
                    this.FolderName = f.Name;
                    if (!String.IsNullOrEmpty(task.Categories)) this.Categories.AddRange(task.Categories.Split(new char[] { ',' }));
                    this.Completed = task.Complete;
                }
                else
                {
                    // Unhandled type
                    this.ValidTaskItem = false; // So we don't add to the collection later
                }
                this.Categories = this.Categories.Select(cat => cat.Trim()).Where(cat => !String.IsNullOrEmpty(cat)).ToList();
            }
            catch
            {
                throw;
            }
        }
And also in the AppointmentsControl.cs:
        /// <summary>
        /// Retrieves tasks for all selected stores
        /// </summary>
        private void RetrieveTasks()
        {
            List<OLTaskItem> tasks = new List<OLTaskItem>();
            foreach (Outlook.Store store in Globals.ThisAddIn.Application.Session.Stores)
            {
                if (Properties.Settings.Default.Accounts != null && Properties.Settings.Default.Accounts.Contains(store.DisplayName))
                {
                    Outlook.Folder todoFolder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderToDo) as Outlook.Folder;
                    try
                    {
                        tasks.AddRange(this.RetrieveTasksForFolder(todoFolder));
                    }
                    catch
                    {
                        // Do nothing (don't try to add deleted task)
                    }
                    // TODO: Shared calendars?
                }
            }
            ...
I don't know I'm the only person that had this small issue.
Hopefully you are able to reproduce and fix this in a next version.

With kind regards,
Joker009
Coordinator
Mar 25, 2015 at 2:59 PM
Thanks for the feedback. Yes, I've only verified the add-in works with Exchange accounts, with external ones YMMV... ;-)

I take note of this and probably include it in a following build. ;-)

Thanks for using my add-in! :-D