to the file and download the file on button click.
Right now what i am doing is i have created a processor that copy the
template file and export data and makes it ready to download for the location.
template file and export data and makes it ready to download for the location.
But instead of running processor and having file copied and saved in different
location, I want to copy the template in memory and export the data in memory and response the stream out.
location, I want to copy the template in memory and export the data in memory and response the stream out.

Leon DRank #851 · 2.6K reputationPosted Mar 13, 2018, 5:15 PM EDT
Debasis SahaRank #21 · 46.5K reputationPosted Mar 13, 2018, 10:59 AM EDT
Istudent RanaRank #4,270 · 354 reputationPosted Mar 13, 2018, 11:06 AM EDT
var fileName = "MyExcelFile.xlsm";
var fileBytes = ExportExcel(myfile);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
{
var ms = new MemoryStream();
string xlReportSheet = ConfigurationManager.AppSettings["WorkSheetName_Report"];
DataTable dtDetails = GetDetails();
string xlDetailsSheet = ConfigurationManager.AppSettings["WorkSheetName_Details"];
{
if (dtNew.Rows.Count > 0)
{
ExportRecapDataNew(dtNew, xlReportSheet, xlPackage);
}
if (dtDetails.Rows.Count > 0)
{
ExportRecapDataRemodel(dtRemdl, xlDetailsSheet, xlPackage);
}
xlPackage.SaveAs(ms);
}
}
Istudent RanaRank #4,270 · 354 reputationPosted Mar 14, 2018, 5:45 AM EDT
I think i am missing a line of code here.
var myfile = HostingEnvironment.MapPath("~/DataFolder/MyExcelFile.xlsm");
var fileName = "MyExcelFile.xlsm";
var fileBytes = ExportExcel(myfile);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
{
var ms = new MemoryStream();
string xlReportSheet = ConfigurationManager.AppSettings["WorkSheetName_Report"];
DataTable dtDetails = GetDetails();
string xlDetailsSheet = ConfigurationManager.AppSettings["WorkSheetName_Details"];
{
if (dtNew.Rows.Count > 0)
{
ExportRecapDataNew(dtNew, xlReportSheet, xlPackage);
xlPackage.Save();
}
if (dtDetails.Rows.Count > 0)
{
ExportRecapDataRemodel(dtRemdl, xlDetailsSheet, xlPackage);
}
}
}