public void ExportReport(XtraReport report, string fileName, string fileType, bool inline) { MemoryStream stream = new MemoryStream(); Response.Clear(); if (fileType == "xls") { report.ExportToXls(stream); } if (fileType == "pdf") { report.ExportToPdf(stream); } if (fileType == "rtf") { report.ExportToRtf(stream); } if (fileType == "csv") { report.ExportToCsv(stream); } Response.ContentType = "application/" + fileType; Response.AddHeader("Accept-Header", stream.Length.ToString()); Response.AddHeader("Content-Disposition", (inline ? "Inline" : "Attachment") + "; filename=" + fileName + "." + fileType); Response.AddHeader("Content-Length", stream.Length.ToString()); //Response.ContentEncoding = System.Text.Encoding.Default; Response.BinaryWrite(stream.ToArray()); Response.End(); }
private void exportFileCsv(XtraReport report) { string reportPath = ""; SaveFileDialog sf = new SaveFileDialog(); sf.FileName = "Save Here.csv"; if (sf.ShowDialog() == DialogResult.OK) { reportPath = Path.GetDirectoryName(sf.FileName) + sf.FileName; try { report.ExportToCsv(sf.FileName); MessageBox.Show("Lưu thành công!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }