/// <summary> /// 由由SQL中讀出PDF內容, 並顯示在瀏覽器上 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult Show(int id) { using (var db = new SignedContractContext()) { var entry = db.SignedContracts.Find(id); return File(entry.SignedFile, "application/pdf"); } }
public ActionResult Pdfs() { using (var db = new SignedContractContext()) { var pdfs = db.SignedContracts.ToList(); return View(pdfs); } }
public HttpResponseMessage PdfGet(int id) { using (var db = new SignedContractContext()) { var entry = db.SignedContracts.Find(id); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(new MemoryStream(entry.SignedFile)); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf"); return result; } }
public ActionResult Index(PostFiles model) { if (!ModelState.IsValid) { return View(model); } var storeFile = new SignedContract(); storeFile.SignedFile = new byte[model.File.InputStream.Length]; storeFile.FileName = model.File.FileName; model.File.InputStream.Read(storeFile.SignedFile, 0, storeFile.SignedFile.Length); using (var db = new SignedContractContext()) { db.SignedContracts.Add(storeFile); db.SaveChanges(); } // now you could pass the byte array to your model and store wherever // you intended to store it return Content("Thanks for uploading the file"); }