C # .net framework 2.
In the third framework, there is a method
protected internal virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName);
What is the equivalent in the second framework? I need to return an excel file based on a byte stream.
Trying to figure out the http://npoi.codeplex.com/ library to export data to excel. The Excel file is read without problems, but more ... When I write memoryStream as an array in Response, as I understand it, it is converted into a string and the output is a text file with the contents of "System.Byte []".
Code:
FileStream fs = new FileStream(Server.MapPath("~/templates/template.xls"), FileMode.Open, FileAccess.Read); // Getting the complete workbook... HSSFWorkbook templateWorkbook = new HSSFWorkbook(fs, true); // Getting the worksheet by its name... var sheet = templateWorkbook.GetSheet("Sheet1"); // Getting the row... 0 is the first row. var dataRow = sheet.GetRow(4); // Setting the value 77 at row 5 column 1 dataRow.GetCell(0).SetCellValue(77); // Forcing formula recalculation... sheet.ForceFormulaRecalculation = true; MemoryStream ms = new MemoryStream(); // Writing the workbook content to the FileStream... templateWorkbook.Write(ms); Response.Clear(); Response.ContentType = "application/vnd.ms-excel"; Response.BufferOutput = true; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "export")); Response.ContentEncoding = Encoding.UTF8; Response.Charset = "utf-8"; Response.Write(ms.ToArray()); Response.Flush(); Response.End();