wondering, if someone can help. I've written this code, which will generate an CSV file spreadsheet and save it to a specified location. I want to display a "Save as" dialogue box by reading the file from the stored location and then asking user, where they want to store it. The excel file is not generated and after click on "Export To CSV" in next window, it will show undefined as a massege! However my problem is the code i've written seems to be outputting the file directly to my browser, so i get all the contents of the CSV file on my browser screen, not displaying the save as dialogue box as expected!
Here is my Code
public ActionResult ExportToCSSReport(List<CEPMobility.CEPServiceProxy.CSSReport> Report)
{
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, System.Text.Encoding.UTF8);
writer.WriteLine("PROJECT NAME,CSS ID,CSS Name,Customer Reprentative Name,CSS Recived Date,CSI,TOP 3 STRENGTH,TOP 3 OFI,Any Other COMMENT");
foreach (CEPMobility.CEPServiceProxy.CSSReport objreport in Report)
{
writer.WriteLine("\"" + objreport.PROJECT_NAME + "\",\"" + objreport.CSS_ID + "\",\"" + objreport.CSS_NAME + "\",\"" + objreport.CUST_REP_NAME + "\",\"" + objreport.CSS_RECIEVED_DT + "\",\"" + objreport.CSI + "\",\"" + objreport.TOP_3_STRENGTH + "\",\"" + objreport.TOP_3_OFI + "\",\"" + objreport.COMMENT + "\"");
}
writer.Flush();
output.Seek(0, SeekOrigin.Begin);
return File(output, "text/csv", "CSSReport.csv");
}
In response to gor, it would show the same undefined message at the top:
public ActionResult ExportToCSSReport(List<CEPMobility.CEPServiceProxy.CSSReport> Report)
{
CEPServiceProxy.CEPDataServiceClient client = null;
client = new CEPServiceProxy.CEPDataServiceClient();
lstCSSReport = client.GetCSSReport(cSS_NAME, in_Cust_ID).ToList();
MemoryStream output = new MemoryStream();
StreamWriter writer = new StreamWriter(output, System.Text.Encoding.UTF8);
writer.WriteLine("PROJECT NAME,CSS ID,CSS Name,Customer Reprentative Name,CSS Recived Date,CSI,TOP 3 STRENGTH,TOP 3 OFI,Any Other COMMENT");
foreach (CEPMobility.CEPServiceProxy.CSSReport objreport in Report)
{
writer.WriteLine("\"" + objreport.PROJECT_NAME + "\",\"" + objreport.CSS_ID + "\",\"" + objreport.CSS_NAME + "\",\"" + objreport.CUST_REP_NAME + "\",\"" + objreport.CSS_RECIEVED_DT + "\",\"" + objreport.CSI + "\",\"" + objreport.TOP_3_STRENGTH + "\",\"" + objreport.TOP_3_OFI + "\",\"" + objreport.COMMENT + "\"");
}
writer.Flush();
output.Seek(0, SeekOrigin.Begin);
Response.AddHeader("Content-Disposition", "attachment;filename=CSSReport.csv");
return File(output, "text/csv", "CSSReport.csv");
}