public FileResult DownLoad(int id) { DocumentAttachments file = helper.FindById(id); string fileName = file.FileNames; byte[] contents = file.FileContent; return(File(contents, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); }
public ActionResult Attachments(DocumentAttachments attach) { if (ModelState.IsValid) { attach.FileUploadId = (int)TempData["File"]; helper.Attach(attach); return(RedirectToAction("Details", "Documents", new { id = attach.FileUploadId })); } return(View(attach)); }
public int Attach(DocumentAttachments Attachments) { 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.CoreDocumentAttachment AttachmentUpload = new DataAccess.CoreDocumentAttachment() { FileAttachmentId = Attachments.FileAttachmentId, FileUploadId = Attachments.FileUploadId, FileNames = System.IO.Path.GetFileName(file.FileName), CoreUserId = 1, DateCreated = DateTime.Now, DeletedBy = "None", DeletedDate = DateTime.Now, BranchId = 1, ProvinceId = 1, FileAttachmentDescription = Attachments.FileAttachmentDescription, LastUpdated = DateTime.Now, IsActive = true, IsRecieved = true, FileContent = Attachments.FileContent }; #endregion #region Binary Reader using (var reader = new System.IO.BinaryReader(file.InputStream)) { AttachmentUpload.FileContent = reader.ReadBytes(file.ContentLength); } #endregion db.CoreDocumentAttachments.Add(AttachmentUpload); } #endregion db.SaveChanges(); } return(Attachments.FileAttachmentId); } }
public void LoadByBusinessID(string businessID) { string regScript = @"ID: '{0}', FileName: '{1}', FileSize:'{2}', Url: '{3}', CreatorName: '{4}', CreateTime: '{5}', Remark:{6}"; DocumentAttachments filter = new DocumentAttachments(); filter.BusinessID = businessID; if (string.IsNullOrEmpty(AttachmentType) == false) { filter.BusinessType = AttachmentType; } IList <B_DocumentAttachments> attachments = B_DocumentAttachmentsOperator.Instance.GetDocAttachmentsList(businessID.ToGuid()); if (attachments.Count == 0 && this.ShowOnly) { this.Visible = false; return; } if (attachments.Count > 0) { StringBuilder sScript = new StringBuilder(""); for (int i = 0; i < attachments.Count; i++) { sScript.Append(this.ClientID + "_Attachments[" + i.ToString() + "] = {"); sScript.Append(string.Format(regScript, new string[] { attachments[i].ID.ToString(), attachments[i].FileName, attachments[i].Size, HttpUtility.UrlEncode(attachments[i].Url), attachments[i].CreatorName, attachments[i].CreateTime.ToShortDateString(), attachments[i].Remark, attachments[i].SystemID.ToString() })); sScript.Append("};"); } sScript.Append(this.ClientID + "_Show();"); ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID, sScript.ToString(), true); } }
public PartialViewResult CreateAttachment() { DocumentAttachments document = new DocumentAttachments(); return(PartialView("_CreateAttachment", document)); }