[HttpGet]
[Route("Excel/{fileID}")]
public IActionResult ExportExcel([FromRoute] string fileID)
{
try
{
string fileStore = Configuration.GetFolder("MasterDataStore");
var files = Directory.GetFiles(fileStore, $"*{fileID}*.xls");
base.HttpContext.Response.Headers.Add("content-disposition", "attachment; filename=Information" + DateTime.Now.Year.ToString() + ".xls");
this.Response.ContentType = "application/octet-stream";
return File(System.IO.File.ReadAllBytes(files[0]), "application/octet-stream", $"{fileID}.xls");
}
catch(Exception ex)
{
return NotFound();
}
}
UI
$scope.download = function (fileName) {
$scope.showAlertData = false;
$scope.alertData = {};
if (fileName != null && fileName != '' && fileName != undefined) {
URIService.GetDataExcel(URIService.GetDownloadExcelFileUrl(fileName))
.success(function (data) {
var file = new Blob([data], {
type: 'application/octet-stream'
});
FileSaver.saveAs(file, fileName+".xls", true);
}).error(function (data, status, headers, config) {
var errorMessage = "";
if (status == "404" || data == undefined) {
errorMessage = "Menu.FileNotFound"
}
else {
errorMessage = "Menu.Error_Message"
}
});
}
}
this.GetDataExcel = function (url) {
var response = $http({
method: 'GET',
url: url,
headers: { 'Content-Type': "application/octet-stream" },
responseType: 'blob'
})
var returnValue = response;
response.success(function (data, status, headers, config) {
}).error(function (data, status, headers, config) {
OnError(data, status, headers, config);
});
return returnValue;
}