I'm using Service Stack for a simple web application.
In this app i need to "export" some content to Excel.. So this is the approach I took:
- I get the HTML content of a table with jQuery a get the HTML content of a table, and send to the service.
- The Service write the content to a file (with some CSS)
- Using the same service, but with a
GET
method, I read the file and make the download withContentType:"application/vnd.ms-excel"
I used this approach without Service Stack in other times, and worked well.. The XLS
file had the right content and some colors.
Now, when I get the file using GET
method (i.e., visiting the url with the browser), the file contents are bad.
ServiceStack let download with some formats: html, csv, jsv, json, xml.
The html format shows up a default report page, the only format that works a little is jsv.
My question is: how can I download the file like plain html file?
Some code:
public class ExcelService : RestServiceBase<Excel>
{
public override object OnGet (Excel request)
{
string file = request.nombre;
//Response.Clear();
HttpResult res = new HttpResult();
res.Headers[HttpHeaders.ContentType] = "application/vnd.ms-excel";
res.Headers[HttpHeaders.ContentDisposition] = "attachment; filename="+file+".xls";
string archivo = System.IO.File.ReadAllText("tmp/"+file+".html");
res.Response = archivo;
return res;
}
}
Thanks in advance