private async void SendMailForm_LoadAsync(object sender, EventArgs e) { Icon = Properties.Resources.DefaultIcon; attachments = new List <FileAttachment>(); // Display the window in the center of the parent window. Location = new Point(Owner.Location.X + (Owner.Width - Width) / 2, Owner.Location.Y + (Owner.Height - Height) / 2); comboBox_Importance.SelectedIndex = 1; comboBox_BodyType.SelectedIndex = 0; if (draftItemId != "") { // Editing a draft item. button_Attachments.Enabled = false; // When sending a draft item, it must be saved to SentItems. checkBox_SaveToSentItems.Checked = true; checkBox_SaveToSentItems.Enabled = false; viewerRequestHelper = new ViewerRequestHelper(); NewEmailMessage draftItem; try { draftItem = await viewerRequestHelper.GetDraftMessageAsync(draftItemId); } catch (Exception ex) { MessageBox.Show(ex.Message, "Office365APIEditor", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); return; } if (comboBox_Importance.InvokeRequired) { comboBox_Importance.Invoke(new MethodInvoker(delegate { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; })); } else { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; } if (comboBox_Importance.InvokeRequired) { comboBox_Importance.Invoke(new MethodInvoker(delegate { comboBox_Importance.SelectedIndex = (int)draftItem.Importance;; })); } else { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; } if (checkBox_RequestDeliveryReceipt.InvokeRequired) { checkBox_RequestDeliveryReceipt.Invoke(new MethodInvoker(delegate { checkBox_RequestDeliveryReceipt.Checked = draftItem.IsDeliveryReceiptRequested; })); } else { checkBox_RequestDeliveryReceipt.Checked = draftItem.IsDeliveryReceiptRequested; } if (checkBox_RequestReadReceipt.InvokeRequired) { checkBox_RequestReadReceipt.Invoke(new MethodInvoker(delegate { checkBox_RequestReadReceipt.Checked = draftItem.IsReadReceiptRequested; })); } else { checkBox_RequestReadReceipt.Checked = draftItem.IsReadReceiptRequested; } if (textBox_To.InvokeRequired) { textBox_To.Invoke(new MethodInvoker(delegate { textBox_To.Text = RecipientsString(draftItem.ToRecipients); })); } else { textBox_To.Text = RecipientsString(draftItem.ToRecipients); } if (textBox_Cc.InvokeRequired) { textBox_Cc.Invoke(new MethodInvoker(delegate { textBox_Cc.Text = RecipientsString(draftItem.CcRecipients); })); } else { textBox_Cc.Text = RecipientsString(draftItem.CcRecipients); } if (textBox_Bcc.InvokeRequired) { textBox_Bcc.Invoke(new MethodInvoker(delegate { textBox_Bcc.Text = RecipientsString(draftItem.BccRecipients); })); } else { textBox_Bcc.Text = RecipientsString(draftItem.BccRecipients); } if (textBox_Subject.InvokeRequired) { textBox_Subject.Invoke(new MethodInvoker(delegate { textBox_Subject.Text = draftItem.Subject; })); } else { textBox_Subject.Text = draftItem.Subject; } if (textBox_Body.InvokeRequired) { textBox_Body.Invoke(new MethodInvoker(delegate { textBox_Body.Text = draftItem.Body.Content; })); } else { textBox_Body.Text = draftItem.Body.Content; } if (comboBox_BodyType.InvokeRequired) { comboBox_BodyType.Invoke(new MethodInvoker(delegate { comboBox_BodyType.SelectedIndex = (int)draftItem.Body.ContentType; })); } else { comboBox_BodyType.SelectedIndex = (int)draftItem.Body.ContentType; } var attachList = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Message, draftItemId); foreach (var attach in attachList) { Dictionary <string, string> fullAttachInfo = await viewerRequestHelper.GetAttachmentAsync(FolderContentType.Message, draftItemId, attach.Id); string tempType = ""; string tempName = ""; string tempContentBytes = ""; foreach (KeyValuePair <string, string> item in fullAttachInfo) { if (item.Key.ToLowerInvariant() == "@odata.type") { tempType = (item.Value == null) ? "" : item.Value.ToString(); } else if (item.Key.ToLowerInvariant() == "name") { tempName = (item.Value == null) ? "" : item.Value.ToString(); } else if (item.Key.ToLowerInvariant() == "contentbytes") { tempContentBytes = (item.Value == null) ? "" : item.Value.ToString(); } } if (tempType == (Util.UseMicrosoftGraphInMailboxViewer ? "#microsoft.graph.fileAttachment" : "#Microsoft.OutlookServices.FileAttachment")) { // This is a FileAttachment attachments.Add(FileAttachment.CreateFromContentBytes(tempName, tempContentBytes)); } } if (button_Attachments.InvokeRequired) { button_Attachments.Invoke(new MethodInvoker(delegate { button_Attachments.Enabled = true; })); } else { button_Attachments.Enabled = true; } } }
private async void AttachmentViewerForm_Load(object sender, EventArgs e) { Icon = Properties.Resources.DefaultIcon; Text = "Attachments for '" + targetItemSubject + "'"; viewerRequestHelper = new ViewerRequestHelper(); List <AttachmentBase> result = new List <AttachmentBase>();; switch (targetFolder.Type) { case FolderContentType.Message: case FolderContentType.MsgFolderRoot: case FolderContentType.Drafts: try { result = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Message, targetItemId); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case FolderContentType.Contact: // In the implementation of OutlookServicesClient, contact item does not have attachment. break; case FolderContentType.Calendar: try { result = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Calendar, targetItemId); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case FolderContentType.Task: try { result = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Task, targetItemId); } catch (Exception ex) { MessageBox.Show(ex.Message); } break; case FolderContentType.DummyCalendarGroupRoot: break; default: break; } foreach (var attachment in result) { // Add new row. string name = attachment.Name; string id = attachment.Id; string contentType = attachment.ContentType; DataGridViewRow itemRow = new DataGridViewRow { Tag = attachment.Id }; itemRow.CreateCells(dataGridView_AttachmentList, new object[] { name, id, contentType }); itemRow.ContextMenuStrip = contextMenuStrip_AttachmentList; if (dataGridView_AttachmentList.InvokeRequired) { dataGridView_AttachmentList.Invoke(new MethodInvoker(delegate { dataGridView_AttachmentList.Rows.Add(itemRow); })); } else { dataGridView_AttachmentList.Rows.Add(itemRow); } } }
private async void SendMailForm_LoadAsync(object sender, EventArgs e) { attachments = new List <ViewerHelper.Data.AttachmentAPI.AttachmentBase>(); comboBox_Importance.SelectedIndex = 1; comboBox_BodyType.SelectedIndex = 0; if (draftItemId != "") { // Editing a draft item. button_Attachments.Enabled = false; // When sending a draft item, it must be saved to SentItems. checkBox_SaveToSentItems.Checked = true; checkBox_SaveToSentItems.Enabled = false; viewerRequestHelper = new ViewerRequestHelper(); var draftItem = await viewerRequestHelper.GetDraftMessageAsync(draftItemId); if (comboBox_Importance.InvokeRequired) { comboBox_Importance.Invoke(new MethodInvoker(delegate { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; })); } else { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; } if (comboBox_Importance.InvokeRequired) { comboBox_Importance.Invoke(new MethodInvoker(delegate { comboBox_Importance.SelectedIndex = (int)draftItem.Importance;; })); } else { comboBox_Importance.SelectedIndex = (int)draftItem.Importance; } if (checkBox_RequestDeliveryReceipt.InvokeRequired) { checkBox_RequestDeliveryReceipt.Invoke(new MethodInvoker(delegate { checkBox_RequestDeliveryReceipt.Checked = draftItem.RequestDeliveryReceipt;; })); } else { checkBox_RequestDeliveryReceipt.Checked = draftItem.RequestDeliveryReceipt; } if (checkBox_RequestReadReceipt.InvokeRequired) { checkBox_RequestReadReceipt.Invoke(new MethodInvoker(delegate { checkBox_RequestReadReceipt.Checked = draftItem.RequestReadReceipt; })); } else { checkBox_RequestReadReceipt.Checked = draftItem.RequestReadReceipt; } if (textBox_To.InvokeRequired) { textBox_To.Invoke(new MethodInvoker(delegate { textBox_To.Text = RecipientsString(draftItem.ToRecipients); })); } else { textBox_To.Text = RecipientsString(draftItem.ToRecipients); } if (textBox_Cc.InvokeRequired) { textBox_Cc.Invoke(new MethodInvoker(delegate { textBox_Cc.Text = RecipientsString(draftItem.CcRecipients); })); } else { textBox_Cc.Text = RecipientsString(draftItem.CcRecipients); } if (textBox_Bcc.InvokeRequired) { textBox_Bcc.Invoke(new MethodInvoker(delegate { textBox_Bcc.Text = RecipientsString(draftItem.BccRecipients); })); } else { textBox_Bcc.Text = RecipientsString(draftItem.BccRecipients); } if (textBox_Subject.InvokeRequired) { textBox_Subject.Invoke(new MethodInvoker(delegate { textBox_Subject.Text = draftItem.Subject; })); } else { textBox_Subject.Text = draftItem.Subject; } if (textBox_Body.InvokeRequired) { textBox_Body.Invoke(new MethodInvoker(delegate { textBox_Body.Text = draftItem.Body; })); } else { textBox_Body.Text = draftItem.Body; } if (comboBox_BodyType.InvokeRequired) { comboBox_BodyType.Invoke(new MethodInvoker(delegate { comboBox_BodyType.SelectedIndex = (int)draftItem.BodyType; })); } else { comboBox_BodyType.SelectedIndex = (int)draftItem.BodyType; } var attachList = await viewerRequestHelper.GetAllAttachmentsAsync(FolderContentType.Message, draftItemId); foreach (var attach in attachList) { Dictionary <string, string> fullAttachInfo = await viewerRequestHelper.GetAttachmentAsync(FolderContentType.Message, draftItemId, attach.Id); string tempType = ""; string tempName = ""; string tempContentBytes = ""; foreach (KeyValuePair <string, string> item in fullAttachInfo) { if (item.Key == "@odata.type") { tempType = (item.Value == null) ? "" : item.Value.ToString(); } else if (item.Key == "Name") { tempName = (item.Value == null) ? "" : item.Value.ToString(); } else if (item.Key == "ContentBytes") { tempContentBytes = (item.Value == null) ? "" : item.Value.ToString(); } } if (tempType == "#Microsoft.OutlookServices.FileAttachment") { // This is a FileAttachment attachments.Add(FileAttachment.CreateFromContentBytes(tempName, tempContentBytes)); } } if (button_Attachments.InvokeRequired) { button_Attachments.Invoke(new MethodInvoker(delegate { button_Attachments.Enabled = true; })); } else { button_Attachments.Enabled = true; } } }