Ich erstelle eine Excel-Datei mit EPPlus-Bibliothek und ich möchte es auf den Client herunterladen. HierEPPlus mit Silverlight
ist ein Beispiel für EPPlus
ExcelPackage pck = new ExcelPackage();
var ws = pck.Workbook.Worksheets.Add("Sample1");
ws.Cells["A1"].Value = "Sample 1";
ws.Cells["A1"].Style.Font.Bold = true;
var shape = ws.Drawings.AddShape("Shape1", eShapeStyle.Rect);
shape.SetPosition(50, 200);
shape.SetSize(200, 100);
shape.Text = "Sample 1 saves to the Response.OutputStream";
pck.SaveAs(HttpContext.Current.Response.OutputStream);
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=Sample1.xlsx");
Dieser Code xls-Datei erstellt und ermöglicht es Client von einer aspx Seite zum Download bereit. Ich habe versucht, XLS-Datei mit "HttpWebRequest" -Klasse von my.aspx Seite anfordern, aber ich bekomme einen Fehler, der sagt "Operation ist nicht gültig aufgrund des aktuellen Status des Objekts".
Wie kann ich diese XLS-Datei vom Server auf den Client herunterladen?