public ActionResult FileUpload() { ExistingFilesModel theModel = GetModelFromSession(); DataTable aTable = theModel.GetUploadedFiles(); ViewData["ExistingFileList"] = aTable.DefaultView; return(View()); }
private ExistingFilesModel GetModelFromSession() { ExistingFilesModel theModel = (ExistingFilesModel)Session["ExistingFilesModel"]; if (theModel == null) { theModel = new ExistingFilesModel(); DataTable aTable = theModel.GetUploadedFiles(); aTable.Columns["File Data"].ColumnMapping = MappingType.Hidden; Session["ExistingFilesModel"] = theModel; } return(theModel); }
public ActionResult GetAFile() { string Attachment = Request.QueryString["ATTACH"]; string ID = Request.QueryString["ID"]; int intID; if (!Int32.TryParse(ID, out intID)) { ViewData["ERROR"] = "Please provide a valid student ID"; return(View("../Shared/Error")); } ExistingFilesModel theModel = GetModelFromSession(); DataTable aTable = theModel.GetUploadedFiles(); DataRow FileRow = aTable.Rows.Find(intID); if (FileRow == null) { ViewData["ERROR"] = "Please provide a valid student ID"; return(View("../Shared/Error")); } string FileName = (string)FileRow["File Name"]; int Size = (int)FileRow["File Size"]; string ContentType = (string)FileRow["Context Type"]; Byte[] Data = (Byte[])FileRow["File Data"]; Response.ContentType = ContentType; StringBuilder SB = new StringBuilder(); if (Attachment == "YES") { SB.Append("attachment; "); } SB.Append("filename="); SB.Append(FileName); Response.AddHeader("Content-Disposition", SB.ToString()); Response.BinaryWrite(Data); Response.Flush(); Response.End(); return(new EmptyResult()); }