I have .pptx files in one location which I need to need to download in client system where ever user want to save or default browser download location.
Controller Code
var fileName = "textFile20210323.pptx";
var filePath = @"\\Depts\IT\TestFolder\";
var fileNamewithPath = $"{filePath}{fileName}";
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/x-mspowerpoint";
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileNamewithPath);
Response.WriteFile(fileNamewithPath);
Response.Flush();
return Json(new { success = "success" }, JsonRequestBehavior.AllowGet);
Script
function DownloadFile(args) {
$.ajax({
type: "POST",
url: "../Home/DownloadFile",
data: { "json": JSON.stringify(args) },
dataType: "json",
beforeSend: function () {
},
success: function (data) {
alert("Success");
}
});
}
Any other approach is acceptable.