public void ProcessRequest(HttpContext context) { string path = "C:/Users/alkes_000/Documents/visual studio 2015/Projects/EnergySimply/EnergySimply/ExcelFile/powertochoose.xlsx"; var file = new FileInfo(path); //FileInfo fi = new FileInfo(openFileDlg.FileName); FileStream fs = new FileStream(file.FullName, FileMode.Open, FileAccess.Read); BinaryReader rdr = new BinaryReader(fs); byte[] fileData = rdr.ReadBytes((int)fs.Length); rdr.Close(); fs.Close(); var savedFileName = "Powertochoose" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; DocumentDal dal = new DocumentDal(); EnergyFile ef = new EnergyFile(); ef.CreateDate = DateTime.Now; ef.FileData = fileData; ef.FileName = savedFileName; var result = dal.SaveFile(ef); context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); }
public void ProcessRequest(HttpContext context) { string path = "C:/Users/alkes_000/Documents/visual studio 2015/Projects/EnergySimply/EnergySimply/ExcelFile/powertochoose.xlsx"; //var basePath = VirtualPathUtility.GetDirectory(context.Request.Url.AbsolutePath); var basePath = context.Request.Url.ToString(); var bp = basePath.Substring(0, basePath.IndexOf("Handlers")); var fullPath = Path.Combine(bp, @"ExcelFile/powertochoose.xlsx"); //var fullPath = Path.Combine(bp, @"ExcelFile/powertochoose.xlsx"); // Hard coded but you can easily get from url parameters // string path = context.Request["path"]; var file = new FileInfo(path); DocumentDal dal = new DocumentDal(); // You should check for file.Exists ! var savedFileName = "Powertochoose" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; EnergySavedFile sf = new EnergySavedFile(); sf.CreateDate = DateTime.Now; sf.FileName = savedFileName; var result = dal.SaveFileRecord(sf); //context.Response.Clear(); //context.Response.AddHeader("content-disposition", // string.Format("attachment; filename=\"{0}\"", savedFileName)); //context.Response.AddHeader("content-disposition", "attachment; filename=excelData.xls"); // context.Response.ContentType = "application/vnd.ms-excel"; // context.Response.WriteFile(file.FullName, false); context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.Page.Title = "View Files"; DocumentDal dal = new DocumentDal(); EnergyPlanDal pdal = new EnergyPlanDal(); gvFiles.DataSource = dal.GetAllFiles(); gvFiles.DataBind(); } }
public void ProcessRequest(HttpContext context) { if (!string.IsNullOrEmpty(context.Request.QueryString["fileId"])) { int itemid = int.Parse(context.Request.QueryString["fileId"].ToString()); DocumentDal dal = new DocumentDal(); var result = dal.GetSavedFile(itemid); var fileItem = dal.GetFile(); context.Response.Clear(); context.Response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}\"", result.FileName)); context.Response.ContentType = "application/vnd.ms-excel"; context.Response.Write(fileItem.FileData); context.Response.Flush(); context.Response.End(); } else { context.Response.ContentType = "text/plain"; context.Response.Write("Fileot be found!"); } }