There is no issue saving file on the disk. I am creating a rest web api to download excel file..my controller file is inherited from ApiController class and I am not able to use httpResponse object directly in my controller..that's why I am not able to use suggested code..
To workaround I have written follwing code.. Please let me know is that is best way or not..
string filePath = HttpRuntime.AppDomainAppPath + "/Content/TempFiles/Report.Xlsx";
workbook.Save(filePath, SaveFormat.Xlsx);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(filePath, FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Report.xlsx"
};
return response;string filePath = HttpRuntime.AppDomainAppPath + "/Content/TempFiles/Report.Xlsx";
workbook.Save(filePath, SaveFormat.Xlsx);
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(filePath, FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "Report.xlsx"
};
return response;