public void ProcessRequest(HttpContext context) { try { var temp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString("d") + ".xlsx"; try { for (int i = 0; i < context.Request.Files.Count; i++) { var file = context.Request.Files[i]; file.SaveAs(temp); var excel = new ExcelManager(); excel.Import(temp); } } finally { System.IO.File.Delete(temp); } context.Response.ContentType = "text/plain"; context.Response.Write("アップロードされました。"); } catch (Exception ex) { context.Response.ContentType = "text/plain"; context.Response.Write(ex.Message); } }
public void ProcessRequest(HttpContext context) { var email = context.Request.Form["email"]; var year = context.Request.Form["year"]; var month = context.Request.Form["month"]; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(year) || string.IsNullOrEmpty(month)) { context.Response.StatusCode = 400; return; } int yearInt; int monthInt; if (int.TryParse(month, out monthInt) && int.TryParse(year, out yearInt)) { var temp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString("d") + ".xlsx"; try { var excel = new ExcelManager(); System.IO.File.Copy(context.Server.MapPath("~/WorkTime_Template.xlsx"), temp); excel.Submit(temp, email, yearInt, monthInt); context.Response.ContentType = "text/plain"; context.Response.Write(string.Format("{0}月度の作業時間を送信しました", month)); } catch (Exception ex) { context.Response.ContentType = "text/plain"; context.Response.Write(ex.Message); } finally { System.IO.File.Delete(temp); } } else { context.Response.StatusCode = 400; return; } }
public void ProcessRequest(HttpContext context) { var email = context.Request.QueryString["email"]; var year = context.Request.QueryString["year"]; var month = context.Request.QueryString["month"]; if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(year) || string.IsNullOrEmpty(month)) { context.Response.StatusCode = 400; return; } int yearInt; int monthInt; if (int.TryParse(month, out monthInt) && int.TryParse(year, out yearInt)) { var temp = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString("d") + ".xlsx"; try { var excel = new ExcelManager(); System.IO.File.Copy(context.Server.MapPath("~/WorkTime_Template.xlsx"), temp); excel.Export(temp, email, yearInt, monthInt); context.Response.AddHeader("content-disposition", "attachment; filename=worktime" + monthInt.ToString("00") + ".xlsx"); context.Response.ContentType = "application/octet-stream"; context.Response.WriteFile(temp); context.Response.Flush(); } finally { System.IO.File.Delete(temp); } } else { context.Response.StatusCode = 400; return; } }