I have a success function which hits the server, send a list of data process it and create an excel file on the processed data. The whole code is working fine but I cannot download file. File is being created on the server.
Client side code is..
MOCService.getFilterExcel($scope.filterExcel).success(function (data, responce) { console.log(responce) return responce; }) Server side:
public ActionResult getFilterExcel(List<FilterExcel> data) { System.Data.OleDb.OleDbConnection conn = null; try { string filename = ""; var oldfilename = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\datafiles\\lswm\\reports.xlsx"; filename = System.Web.HttpContext.Current.Request.PhysicalApplicationPath + "\\datafiles\\report\\report" + HttpContext.User.Identity.Name + ".xls"; System.IO.File.Copy(oldfilename, filename, true); conn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filename + "; Extended Properties=\"Excel 12.0 Xml;HDR=NO\";"); conn.Open(); //return null; int i = 3; foreach (var item in data) { var strsql = "insert into [Report$C" + (i) + ":L" + (i) + "] (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10)values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')"; var cmd = conn.CreateCommand(); cmd.CommandText = string.Format(strsql, item.ccrfNo, item.requestDate, item.requestedBy, item.title, item.changeImpact, item.plant, item.division, "", item.taskStatus, item.currentPhase ); var rowcount = cmd.ExecuteNonQuery(); i++; } } catch(Exception ex) { } finally { if (conn != null && conn.State == ConnectionState.Open) conn.Close(); } return File(Request.PhysicalApplicationPath + "\\datafiles\\report\\report" + HttpContext.User.Identity.Name + ".xls", "Application/MS-excel", "report" + HttpContext.User.Identity.Name + ".xls"); } And if I hit the action method directly from URL then the file is downloaded but via application it does not download.
location.href = ...in the success callback to call a method that returns the file