private void button_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if (_graphClient == null) { return; } string[] filesAndDictionaries = (string[])e.Data.GetData(System.Windows.DataFormats.FileDrop, false); List <string> files = getListWithOnlyFiles(filesAndDictionaries); List <ModelViewAttachment> modelViewAttachments = new List <ModelViewAttachment>(); InitializeModelViewAttachments(modelViewAttachments, files); OpenViewModel(_graphClient, "", "", modelViewAttachments); #region Local Methode List <string> getListWithOnlyFiles(string[] localFilesAndDictionaries) { List <string> localFiles = new List <string>(); for (int i = 0; i < localFilesAndDictionaries.Length; i++) { // get the file attributes for file or directory FileAttributes attr = System.IO.File.GetAttributes(localFilesAndDictionaries[i]); if (attr.HasFlag(FileAttributes.Directory)) { continue;//wenn it is a folder, then spring over } else { localFiles.Add(localFilesAndDictionaries[i]); } } return(localFiles); } void InitializeModelViewAttachments(List <ModelViewAttachment> localModelViewAttachments, List <string> localFiles) { foreach (string file in localFiles) { ModelViewAttachment modelViewAttachment = new ModelViewAttachment(); modelViewAttachment.DisplayName = Path.GetFileName(file); modelViewAttachment.FilePath = file; localModelViewAttachments.Add(modelViewAttachment); } } #endregion }
private void button1_Click(object sender, EventArgs e) { if (_graphClient == null) { return; } bool IsOutlookClosed = PopWarning(shouldPopWarning: !processRunning("OUTLOOK"), message: "Bitte OUTLOOK öffnen"); if (IsOutlookClosed) { return; } Mail mail = new Mail(); bool IsMailNotSelected = PopWarning(shouldPopWarning: !mail.ItemSelected, message: "Bitte eine Email anwählen"); if (IsMailNotSelected) { return; } List <ModelViewAttachment> modelViewAttachments = new List <ModelViewAttachment>(); InitializeModelViewAttachments(mail, modelViewAttachments, CreateTempDictionary()); OpenViewModel(_graphClient, "", mail.MailSubject, modelViewAttachments); //Directory.Delete(localTempDirectory, true); #region Local Methode bool PopWarning(bool shouldPopWarning, string message) { bool popWarning; if (shouldPopWarning) { const string caption = "Warnung"; var result = System.Windows.Forms.MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); popWarning = true; return(popWarning); } else { popWarning = false; return(popWarning); } } bool processRunning(string processName) { foreach (Process proc in Process.GetProcesses()) { if (proc.ProcessName.Contains(processName)) { return(true); } } return(false); } string CreateTempDictionary() { string localTempDirectory = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"\TempMicrosoftPlannerAttachments\", Guid.NewGuid(), "\\"); System.IO.Directory.CreateDirectory(localTempDirectory); return(localTempDirectory); } void InitializeModelViewAttachments(Mail localMail, List <ModelViewAttachment> localModelViewAttachments, string localTempDirectory) { foreach (Microsoft.Office.Interop.Outlook.Attachment attachment in localMail.Attachments) { if (attachment.Size < 10000 && attachment.FileName.Contains("image00")) { continue; } ModelViewAttachment modelViewAttachment = new ModelViewAttachment(); localModelViewAttachments.Add(modelViewAttachment); modelViewAttachment.DisplayName = attachment.DisplayName; modelViewAttachment.FilePath = string.Concat(localTempDirectory, attachment.FileName); attachment.SaveAsFile(modelViewAttachment.FilePath); } ModelViewAttachment modelViewAttachment1 = new ModelViewAttachment(); modelViewAttachment1.DisplayName = "Mail"; modelViewAttachment1.FilePath = string.Concat(localTempDirectory, "Mail.msg"); localMail.Item.SaveAs(modelViewAttachment1.FilePath); localModelViewAttachments.Add(modelViewAttachment1); } #endregion }