private void AddAttachment(object o) { //Validate basic info if (null == o) { return; } string[] filesPath = null; var filePath = o as string; if (null == filePath) { filesPath = o as string[]; if (null == filesPath) { return; } } else { filesPath = new string[] { filePath } }; //Validate id generated if (string.IsNullOrEmpty(MailMessage.ID)) { MailMessage.ID = MainVm.CreateId(); } //Ensure cache folder is generated string folder = EnsureDraftCacheFolder(MailMessage.ID); //Attach file string copyTarget = null; foreach (var path in filesPath) { FileInfo info = new FileInfo(path); if (!info.Exists) { return; } try { copyTarget = folder.CombinePath(info.Name); if (File.Exists(copyTarget)) { Messenger.Default.Send(new DisplayMessage("Exist file!", DisplayType.Toast)); } else { info.CopyTo(copyTarget); MailMessage.Attachments.Add(info.Name); } } catch (Exception e) { Messenger.Default.Send(new DisplayMessage(e.Message, DisplayType.Toast)); } } }