/// <summary> /// This method creates the tasks, assigns and generates the html content to be attached in the assigned tasks section of the MOM /// </summary> /// <returns></returns> private String assignTasks() { Dictionary <int, String> taskList = new Dictionary <int, string>(); String returnHTML = ""; foreach (DataGridViewRow dr in dataGridView_action_items.Rows) { try { //Use the Outlook application object created in the previous form Outlook.TaskItem taskObj = app.CreateItem(Outlook.OlItemType.olTaskItem) as Outlook.TaskItem; taskObj.Subject = dr.Cells[0].Value.ToString(); taskObj.Body = dr.Cells[0].Value.ToString(); taskObj.DueDate = DateTime.Parse(dr.Cells[1].Value.ToString()); //taskObj.Owner = dr.Cells[4].Value.ToString(); taskObj.Assign(); taskObj.Recipients.Add(dr.Cells[4].Value.ToString()); taskObj.ReminderSet = true; taskObj.ReminderTime = Convert.ToDateTime(taskObj.DueDate.ToShortDateString() + " " + comboBox_reminder.Text.Trim()); if (!dr.Cells[3].Value.ToString().Equals("")) { taskObj.Attachments.Add(dr.Cells[3].Value.ToString(), Outlook.OlAttachmentType.olByValue, 1, dr.Cells[3].Value.ToString()); } taskObj.Send(); //Create the HTML content for the MOM returnHTML += "<tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;mso-yfti-lastrow:yes'>" + "<td style='padding:.75pt .75pt .75pt .75pt'>" + "<p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm'><b><span style='font-size:8.0pt;font-family:\"Book Antiqua\",\"serif\"'>" + "<a href=Outlook:" + taskObj.EntryID + ">" + taskObj.Subject + "</a>" + "</span></b></p> </td>" + "<td style='padding:.75pt .75pt .75pt .75pt'>" + "<p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom: 3.0pt;margin-left:0cm'><span style='font-size:8.0pt;font-family:\"Book Antiqua\",\"serif\"'>" + taskObj.Owner + "</span></b></p> </td>" + "<td style='padding:.75pt .75pt .75pt .75pt'>" + "<p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom: 3.0pt;margin-left:0cm'><span style='font-size:8.0pt;font-family:\"Book Antiqua\",\"serif\"'>" + taskObj.DueDate.ToShortDateString() + "</span></b></p> </td>" + " </tr>"; //taskList.Add(dr.Index,taskObj.EntryID); } catch (Exception ex) { MessageBox.Show("Error Sending Task" + ex.ToString(), "Error", MessageBoxButtons.OK); } } return(returnHTML); /*Outlook.MailItem mailObj = FilterForm.app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem; * mailObj.To = "*****@*****.**"; * String htmlBody=mailObj.HTMLBody; * foreach(KeyValuePair<int,String> kvp in taskList) * { * mailObj.HTMLBody = "<a href=Outlook:" + kvp.Value + ">" + kvp.Key.ToString() + "</a>"; * }*/ //mailObj.HTMLBody += htmlBody; //mailObj.Send(); }
public void Save(IToDo t) { Outlook.TaskItem item = ((OutlookToDo)t).TaskItem; item.Assign(); item.Save(); sync(); }