Linked Questions

Popular Questions

I am trying to download a simple xlsx file using web api but the file is always corrupt and I am yet to figure out why.I am using C# ClosedXML.Excel and following a basic example which can be found here:

ClosedXml examples

[SwaggerResponse(491, "TokenInvalid")]
public async Task<IHttpActionResult> GetCampaignContactPointsExcel(int id, int frequency, string txtFrequency)
    var wb = new XLWorkbook();
    var ws1 = wb.Worksheets.Add("Sheet1");

    var ws2 = wb.Worksheets.Add("Sheet2");


    var responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
    using (var memoryStream = new MemoryStream())
            responseMessage.Content = new ByteArrayContent(memoryStream.ToArray());
            responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            responseMessage.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                    FileName = "ContactPoints.xlsx"
            return ResponseMessage(responseMessage);

I am also using swagger and when I click on the link it downloads the file and opens it as a xlsx file but it always says it's corrupt.

Related Questions