public byte[] GetAttachmentFromMail(String mailbox, UInt64 gmMailID, String attachmentName) { Mailbox targetMailbox = this.GetMailbox(mailbox); Int32 mailUID = this.GetMailUID(mailbox, gmMailID); AttachmentCollection attachmentsInMail = targetMailbox.Fetch.UidMessageObject(mailUID).Attachments; MimePart desiredAttachment; try { desiredAttachment = attachmentsInMail.Cast <MimePart>() .Where <MimePart>(x => x.Filename == attachmentName) .Single <MimePart>(); } catch (System.InvalidOperationException systemException) { throw new InvalidAttachmentException(systemException.Message, "Se pide un archivo adjunto que no existe, o más de un adjunto posee el mismo nombre."); } return(desiredAttachment.BinaryContent); }
private static void ShallowCloneAttachments(WorkItem item, AttachmentCollection attachments, Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem targetWorkItem, ICollection<string> attachmentsToClean) { var downloadClient = new WebClient {UseDefaultCredentials = true}; var tempDownloadPath = Path.GetTempPath(); foreach (var existingAttachment in attachments.Cast<Attachment>()) { var tempFile = Path.Combine(tempDownloadPath, existingAttachment.Name); downloadClient.DownloadFile(existingAttachment.Uri, tempFile); var attachmentComment = string.IsNullOrWhiteSpace(existingAttachment.Comment) ? existingAttachment.Comment : string.Format("Migrated from work item {0}", item.Id); var clonedAttachment = new Attachment(tempFile, attachmentComment); targetWorkItem.Attachments.Add(clonedAttachment); attachmentsToClean.Add(tempFile); } }