private void SetContentDisposition(PropertyContextFacade context) { IObjectFacade no = context.Property.GetValue(context.Target); string cd = no == null || string.IsNullOrWhiteSpace(no.GetAttachment().ContentDisposition) ? AttachmentContextFacade.DefaultContentDisposition : no.GetAttachment().ContentDisposition; string fn = no != null?no.GetAttachment().FileName : AttachmentContextFacade.DefaultFileName; ContentDisposition = new ContentDispositionHeaderValue(cd) { FileName = fn }; }
protected FileContentResult AsFile(IObjectFacade domainObject) { var fileAttachment = domainObject.GetAttachment(); if (fileAttachment != null) { bool addHeader = !string.IsNullOrWhiteSpace(fileAttachment.ContentDisposition); if (addHeader) { string dispositionValue = string.Format("{0}; filename={1}", fileAttachment.ContentDisposition, fileAttachment.FileName); Response.AddHeader("Content-Disposition", dispositionValue); } Stream stream = fileAttachment.Content; using (var br = new BinaryReader(stream)) { byte[] bytes = br.ReadBytes((int)stream.Length); var mimeType = fileAttachment.MimeType ?? "image/bmp"; // need to use different File overloads or will end up with two content-disposition headers return(addHeader ? File(bytes, mimeType) : File(bytes, mimeType, fileAttachment.FileName)); } } var byteArray = domainObject.GetDomainObject <object>() as byte[]; return(File(byteArray, AttachmentContextFacade.DefaultMimeType)); }
private void SetContentType(PropertyContextFacade context) { IObjectFacade no = context.Property.GetValue(context.Target); Func <string> defaultMimeType = () => no == null ? AttachmentContextFacade.DefaultMimeType : no.GetAttachment().DefaultMimeType(); string mtv = no == null || string.IsNullOrWhiteSpace(no.GetAttachment().MimeType) ? defaultMimeType() : no.GetAttachment().MimeType; contentType = new MediaTypeHeaderValue(mtv); }
public MediaTypeHeaderValue GetAttachmentMediaType() { IObjectFacade no = assoc.GetValue(objectFacade); var attachment = no == null ? null : no.GetAttachment(); string mtv = attachment == null || string.IsNullOrWhiteSpace(attachment.MimeType) ? "" : attachment.MimeType; return(new MediaTypeHeaderValue(string.IsNullOrWhiteSpace(mtv) ? attachment.DefaultMimeType() : mtv)); }
private void SetStream(PropertyContextFacade context) { IObjectFacade no = context.Property.GetValue(context.Target); AsStream = no != null?no.GetAttachment().Content : new MemoryStream(); }
protected string GetAttachmentFileName(PropertyContextFacade context) { IObjectFacade no = context.Property.GetValue(context.Target); return(no != null?no.GetAttachment().FileName : "UnknownFile"); }
protected FileContentResult AsFile(IObjectFacade domainObject) { var fileAttachment = domainObject.GetAttachment(); if (fileAttachment != null) { bool addHeader = !string.IsNullOrWhiteSpace(fileAttachment.ContentDisposition); if (addHeader) { string dispositionValue = string.Format("{0}; filename={1}", fileAttachment.ContentDisposition, fileAttachment.FileName); Response.AddHeader("Content-Disposition", dispositionValue); } Stream stream = fileAttachment.Content; using (var br = new BinaryReader(stream)) { byte[] bytes = br.ReadBytes((int) stream.Length); var mimeType = fileAttachment.MimeType ?? "image/bmp"; // need to use different File overloads or will end up with two content-disposition headers return addHeader ? File(bytes, mimeType) : File(bytes, mimeType, fileAttachment.FileName); } } var byteArray = domainObject.GetDomainObject<object>() as byte[]; return File(byteArray, AttachmentContextFacade.DefaultMimeType); }