download excel file using c# mvc 5 jquery

download excel file using c# mvc 5 jquery

We can download files using the below mvc 5 code or jQuery code both code are woking. C# code work in server side but jQuery on client only.

Download Excel File using C# MVC 5 .Net

public ActionResult DownloadExcelFile(string Orgfile = "DownloadSampleFile.xlsx")
     string filePath = Server.MapPath("~/UploadedExcelFolder/DownloadSampleFile.xlsx");
     System.IO.FileInfo file = new System.IO.FileInfo(filePath);

     if (file.Exists)
          Response.AddHeader("Content-Disposition", "attachment; filename=" + Orgfile);
          Response.AddHeader("Content-Length", file.Length.ToString());
          Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
       return RedirectToAction("Success");


 Download Excel File using jQuery

$('#btnDownloadExcel').click(function () {
        window.location.href = "UploadedExcelDocuments/DownloadSampleFile.xlsx";

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - and
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
Post a Comment Powered by Blogger.
ASK Questions