public override IList <CommunicationAttachment> GetAttachments() { return(_resumeContents == null ? null : new List <CommunicationAttachment> { new ContentAttachment(_resumeContents, _resumeFileName, MediaType.GetMediaTypeFromExtension(Path.GetExtension(_resumeFileName), MediaType.Text)) }); }
public void AddAttachments(IList <string> fileAttachments) { if (_attachments == null) { _attachments = new List <CommunicationAttachment>(); } foreach (var attachment in fileAttachments) { _attachments.Add((new FileAttachment(attachment, MediaType.GetMediaTypeFromExtension(Path.GetExtension(attachment), MediaType.Text)))); } }
private ContentAttachment GetResumeFile(EmployerMemberView view) { var resumeFile = _employerResumeFilesQuery.GetResumeFile(view); // Save the contents into a stream. var stream = new MemoryStream(); stream.Write(resumeFile.Contents, 0, resumeFile.Contents.Length); stream.Position = 0; return(new ContentAttachment(stream, resumeFile.Name, MediaType.GetMediaTypeFromExtension(Path.GetExtension(resumeFile.Name), MediaType.Text))); }
public void AddAttachments(TempFileCollection tempFileAttachments) { _tempFileAttachments = tempFileAttachments; if (_attachments == null) { _attachments = new List <CommunicationAttachment>(); } foreach (var attachment in _tempFileAttachments.FilePaths) { _attachments.Add(new FileAttachment(attachment, MediaType.GetMediaTypeFromExtension(Path.GetExtension(attachment), MediaType.Text))); } }
/// <summary> /// Gets an existing FileReference or creates a new one with the specified data and metadata. This method /// filters out duplicates on two levels: /// 1) The same data is not stored in the file system twice. Instead multiple FileReference instances /// are given the same FileData instance (which corresponds to one physical file being stored). /// 2) The same metadata is not stored in the FileReference table twice. If the metadata matches exactly /// this method returns the existing FileReference. /// </summary> private FileReference CreateFileReference(FileType fileType, string fileName, string defaultContentType, int contentLength, byte[] contentHash, out bool isExistingFile) { fileName = Path.GetFileName(fileName); // Strip the path, if any. var mediaType = MediaType.GetMediaTypeFromExtension(Path.GetExtension(fileName), defaultContentType); // First look for an existing file reference. var fileReference = _repository.GetFileReference(fileType, fileName, mediaType, contentLength, contentHash); if (fileReference != null) { isExistingFile = true; return(fileReference); } // Look for data corresponding to the file. var fileData = _repository.GetFileData(fileType, contentLength, contentHash); if (fileData == null) { // Need to create and save. isExistingFile = false; fileData = new FileData { Id = Guid.NewGuid(), FileType = fileType, FileExtension = Path.GetExtension(fileName).ToLower(), ContentLength = contentLength, ContentHash = contentHash }; _repository.CreateFileData(fileData); } else { isExistingFile = true; } fileReference = new FileReference { Id = Guid.NewGuid(), CreatedTime = DateTime.Now, MediaType = mediaType, FileName = fileName, FileData = fileData }; _repository.CreateFileReference(fileReference); return(fileReference); }
private ContentAttachment GetResumeFile(IEnumerable <EmployerMemberView> views) { var resumeFile = _employerResumeFilesQuery.GetResumeFile(views); var fileName = resumeFile.Name; // Save the contents of the zip file into a stream. var stream = new MemoryStream(); resumeFile.Save(stream); stream.Position = 0; return(new ContentAttachment(stream, fileName, MediaType.GetMediaTypeFromExtension(Path.GetExtension(fileName), MediaType.Text))); }
private void AddAttachments(TemplateEmail email, ICollection <FileReference> fileReferences) { if (fileReferences != null && fileReferences.Count > 0) { var attachments = new List <CommunicationAttachment>(); foreach (var fileReference in fileReferences) { var stream = _filesQuery.OpenFile(fileReference); attachments.Add(new ContentAttachment(stream, fileReference.FileName, MediaType.GetMediaTypeFromExtension(Path.GetExtension(fileReference.FileName), MediaType.Text))); } email.AddAttachments(attachments); } }