简体   繁体   中英

Exporting excel reports

I have a software ready in which i am exporting excel reports through code in ASP.NET . Right now I am developing the entire on Localhost , so when i export the report it is downloading on my PC . I am just concerned if i run it on live server and than I export the excel reports , will it download on my Pc or on server.

  public ActionResult ExportToExcel()
        {
            if (!General.ValidateSession())
            {
                return RedirectToAction("Login", "User");
            }
            string fDate = TempData["FromDate"].ToString();
            string tDate = TempData["toDate"].ToString();
            var grdview = new GridView();
            grdview.DataSource = this.GetList();
            grdview.DataBind();
            Response.ClearContent();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment; filename= " + fDate + " - " + tDate + ".xls ");
            Response.ContentType = "application/ms-excel";
            Response.Charset = "";
            StringWriter strWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);
            grdview.RenderControl(htmlWriter);
            Response.Output.Write(strWriter.ToString());
            Response.Flush();
            Response.End();
            return RedirectToAction("DateRecords");
        }

when you host the application on server and On EXCEL Export, file will be downloaded to the user's machine from the server. not on to your local machine!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM