In my one of .Net Framework 4.5
project, i had been creating response (file download
) as following
.Net Framework 4.5 version
public virtual HttpResponseMessage ExportExcel()
{
...................
....................
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK);
Stream stream = new MemoryStream(bytes);
response.Content = new StreamContent(stream);
var cookie = new CookieHeaderValue("customValue", "true");
cookie.Path = "/";
response.Headers.AddCookies(new CookieHeaderValue[] { cookie });
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = ExportFileName
};
return response;.
}
As you can see i am adding cookie, Header ContentType etc.
Here is my ported .Net Core version.
public virtual ActionResult ExportExcel()
{
........
.......
byte[] bytes = _svc.Export(excelTemplatePath, ExcelColumns);
Response.StatusCode = 200;
Response.Cookies.Append("customValue", "true");
Response.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet").ToString();
return File(bytes, "application/x-msdownload", "");
}
}
Issue:
1- I could not find the way to set
ContentDisposition
2- There is no
Response.Content
(I could not find Response.Content = new StreamContent(stream) in .Net Core.