public void ExportToExcel() { if (Session["LoggedUserName"] != null && Session["IsAdmin"] == "1") { BugBusinessLayer.BugBusinessLayerControl bbc = new BugBusinessLayer.BugBusinessLayerControl(); List<BugModel> defects = bbc.Defects.ToList(); var grid = new GridView(); grid.DataSource = from data in defects //take Specific content only. select new { DefectId = data.DefectId, Program = data.Program, ProblemSummary = data.ProblemSummary, Problem = data.Problem, FunctionalArea = data.FunctionalArea, Status = data.SqlStatus, Priority = data.Priority, ReportedBy = data.ReportedBy, ReportedOn = data.SqlDate, AssignedTo = data.AssignedTo }; grid.DataBind(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=Exported_Defects.xls"); Response.ContentType = "application/excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); grid.RenderControl(htw); Response.Write(sw.ToString()); Response.End(); } else RedirectToAction("Login", "Bh"); }
public ActionResult IndexUsers() { if (Session["LoggedUserName"] != null && Session["IsAdmin"] == "1") // TODO - Uncomment. { users = null; BugBusinessLayer.BugBusinessLayerControl obc = new BugBusinessLayer.BugBusinessLayerControl(); users = obc.Users.ToList(); return View(users); } return RedirectToAction("Login", "Bh"); }
public ActionResult ExportToCSV() { if (Session["LoggedUserName"] != null && Session["IsAdmin"] == "1") { StringWriter sw = new StringWriter(); sw.WriteLine("\"DefectId\",\"Program\",\"ProblemSummary\",\"Problem\",\"FunctionalArea\",\"Status\",\"Priority\",\"ReportedBy\",\"Date\",\"AssignedTo\""); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment;filename=Exported_Defects.csv"); Response.ContentType = "text/csv"; BugBusinessLayer.BugBusinessLayerControl bbc = new BugBusinessLayer.BugBusinessLayerControl(); List<BugModel> defects = bbc.Defects.ToList(); foreach (var data in defects) { sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\",\"{6}\",\"{7}\",\"{8}\",\"{9}\"", data.DefectId, data.Program, data.ProblemSummary, data.Problem, data.FunctionalArea, data.SqlStatus, data.Priority, data.ReportedBy, data.SqlDate, data.AssignedTo)); } Response.Write(sw.ToString()); Response.End(); } return RedirectToAction("Login", "Bh"); }