I'm using mysite.jsreportsonline.net to create a csv the end user downloads. On the jsreports site under my login, it functions as it should be prompting me to download the file with the .csv extension. For some reason in my MVC 4 application, it prompts for the download, but doesn't add the .csv extension. in my controller I am pulling the report from mysite.jsreportonline.net with my login credentials. Any clues as tyo why this is happening?
Asked
Active
Viewed 244 times
2 Answers
0
jsreport response headers include something like
Content-Disposition: attachment;filename=report.csv
This instructs browser to open download dialog for report.csv.
If I understand it correctly you make a post request to jsreport from the controller and then return the stream you get back. You need to make sure you add such a header also to your response.

Jan Blaha
- 3,069
- 1
- 22
- 35
-
I'm using `ReportingService` which allows for the url string, username and password and `_reportingService.RenderAsync` which allows for shortid and input data. tried adding `Response.AddHeader` but that didn't work. Also tried `FileExtension = "csv";` and that didn't work either. – Jeff Mcbride Nov 13 '15 at 16:18
-
You seems to have rather a common problem of returning files from mvc controllers. You should be able to return jsreport stream as any other. Did you try something like this? http://stackoverflow.com/a/5830215/1660996 – Jan Blaha Nov 13 '15 at 16:39
-
I'm adding `Response.AppendHeader("content-Disposition: attachment; filename=filename.csv", report.ToString());` and what that returns is "filename.csv- jsreport.Client.Report" as the filename to save as. – Jeff Mcbride Nov 13 '15 at 19:27
-
Still not working. Using `System.Web.HttpContext.Current.Application.Remove("- jsreport.Client.Report");`, `System.Web.HttpContext.Current.Response.ClearContent();`, `System.Web.HttpContext.Current.Response.ClearHeaders();`, `Response.AppendHeader("Content-Disposition: " + "attachment; filename=report.csv", report.ToString());`, `System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";` with no luck. Still wants to save it as "report.csv- jsreport.Client.Report" Anyone out there got this to work in an MVC 4 application? – Jeff Mcbride Nov 17 '15 at 23:32
0
So I was using Response.AppendHeader
wrong. Here's how it should have been coded:
Response.AppendHeader("Content-Disposition", "attachment; filename=filename.csv");
Response.ContentType = "application/octet-stream";

Jeff Mcbride
- 453
- 2
- 6
- 19