public void ExportToCSV(DataTable dtExportToCSV, string fileName)
{
string strCSVSeparator = Translate("/templates/useradministration/csvseparator");
HttpContext context = HttpContext.Current;
context.Response.Clear();
//Added for Special Character Export
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF32;
foreach (DataColumn dcExportToCSV in dtExportToCSV.Columns)
{
context.Response.Write("\"" + dcExportToCSV.ColumnName + "\"" + strCSVSeparator);
}
// In Org and Group search if we do not leave a line , the data comes in the same line as header
context.Response.Write(Environment.NewLine);
foreach (DataRow drExportToCSV in dtExportToCSV.Rows)
{
for (int i = 0; i < dtExportToCSV.Columns.Count; i++)
{
context.Response.Write("\"" + drExportToCSV[i].ToString() + "\"" + strCSVSeparator);
}
context.Response.Write(Environment.NewLine);
}
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
context.Response.End();
}
public void ExportToSpreadsheet(DataTable dtExportToExcel, string fileName)
{
string strCSVSeparator = Translate("/templates/useradministration/csvseparator");
HttpContext context = HttpContext.Current;
context.Response.Clear();
//Added for Special Character Export
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF32;
foreach (DataColumn column in dtExportToExcel.Columns)
{
context.Response.Write("\"" + column.ColumnName + "\"" + strCSVSeparator);
}
context.Response.Write(Environment.NewLine);
context.Response.Write(Environment.NewLine);
foreach (DataRow row in dtExportToExcel.Rows)
{
for (int i = 0; i < dtExportToExcel.Columns.Count; i++)
{
context.Response.Write("\"" + row[i].ToString() + "\"" + strCSVSeparator);
}
context.Response.Write(Environment.NewLine);
}
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
context.Response.End();
}
public void ExportToCSVTitle(DataTable dtExportToCSV, string fileName, List
{
string strCSVSeparator = Translate("/templates/useradministration/csvseparator");
HttpContext context = HttpContext.Current;
context.Response.Clear();
//Added for Special Character Export
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF32;
foreach (string title in listTitle)
{
context.Response.Write("\"" + title + "\"" + strCSVSeparator);
context.Response.Write(Environment.NewLine);
}
context.Response.Write(Environment.NewLine);
foreach (DataColumn dcExportToCSV in dtExportToCSV.Columns)
{
context.Response.Write("\"" + dcExportToCSV.ColumnName + "\"" + strCSVSeparator);
}
// In Org and Group search if we do not leave a line , the data comes in the same line as header
context.Response.Write(Environment.NewLine);
foreach (DataRow drExportToCSV in dtExportToCSV.Rows)
{
for (int i = 0; i < dtExportToCSV.Columns.Count; i++)
{
context.Response.Write("\"" + drExportToCSV[i].ToString() + "\"" + strCSVSeparator);
}
context.Response.Write(Environment.NewLine);
}
context.Response.ContentType = "text/csv";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + ".csv");
context.Response.End();
}
--
Thanks & Regards
Ch Pavankumar
08122629197