public ActionResult NominationDataExport() { _repoResponse = new RepositoryResponse(); _nominationRepo = new NominationRepo(); string _loggedInUserID = System.Web.HttpContext.Current.Session["UserID"].ToString(); _repoResponse = _nominationRepo.LoadNomination(_loggedInUserID, ""); if (_repoResponse.success) { DataSet ds = Assistant.ToDataSet(_repoResponse.Data); string path = HostingEnvironment.MapPath("~/bin/Pdf/"); string fName = "SOM_NominationDetails_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".xlsx"; if (Assistant.DatasetToExcelExport(ds, path, fName, 5, "NominationDetails")) // 4th parameter is field Count { byte[] fileBytes = System.IO.File.ReadAllBytes(path + "" + fName); return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fName)); } } return(Json(new { success = _repoResponse.success, message = _repoResponse.message })); }