public static byte[] GetReportGridBytes(String targetType, DataSet dataSet) { if (targetType == "PDF") { using (var stream = new MemoryStream()) { var pdfDoc = new Document(); var writer = PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); foreach (DataTable dataTable in dataSet.Tables) { var table = GetPdfGrid(dataTable); pdfDoc.Add(table); } pdfDoc.Close(); return(stream.ToArray()); } } if (targetType == "Excel") { return(ExcelUtil.ConvertToExcel(dataSet)); } if (targetType == "CSV") { var dataTable = dataSet.Tables.Cast <DataTable>().FirstOrDefault(); return(ExcelUtil.ConvertToCSV(dataTable)); } return(null); }