public FileResult DownLoad(int id) { LeadAttachments file = helper.FindById(id); string fileName = file.FileNames; byte[] contents = file.FileContent; return(File(contents, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); }
public ActionResult LeadAttachment(LeadAttachments attach) { if (ModelState.IsValid) { attach.LeadId = (int)TempData["Lead"]; helper.Attach(attach); return(RedirectToAction("Details", "Leads", new { id = attach.LeadId, area = "Leads" })); } return(View(attach)); }
public int Attach(LeadAttachments leadAttachments) { using (DataAccess.JazMaxDBProdContext db = new DataAccess.JazMaxDBProdContext()) { var context = HttpContext.Current; for (int i = 0; i < context.Request.Files.Count; i++) { var file = context.Request.Files[i]; #region Content Length if (file != null && file.ContentLength > 0) { #region AttachmentFileUpload DataAccess.CoreLeadAttachment AttachmentUpload = new DataAccess.CoreLeadAttachment() { FileAttachmentId = leadAttachments.FileAttachmentId, LeadId = leadAttachments.LeadId, FileNames = System.IO.Path.GetFileName(file.FileName), CoreUserId = 1, DateCreated = DateTime.Now, DeletedBy = "None", DeletedDate = DateTime.Now, BranchId = 1, ProvinceId = 1, FileAttachmentDescription = leadAttachments.FileAttachmentDescription, LastUpdated = DateTime.Now, IsActive = true, IsRecieved = true, FileContent = leadAttachments.FileContent }; #endregion #region Binary Reader using (var reader = new System.IO.BinaryReader(file.InputStream)) { AttachmentUpload.FileContent = reader.ReadBytes(file.ContentLength); } #endregion db.CoreLeadAttachments.Add(AttachmentUpload); } #endregion db.SaveChanges(); } return(leadAttachments.FileAttachmentId); } }
public PartialViewResult AddAttachment() { LeadAttachments document = new LeadAttachments(); return(PartialView("_AddAttachment", document)); }