<pre lang="c#"> public static void ExportToFile(string filename, string filepath, System.Data.DataTable dtResult, string webServerFileLink) { string sFlag = "Error"; StreamWriter sw = new StreamWriter(filepath, false); StringBuilder dataToExport = new StringBuilder(); sw.WriteLine(Convert.ToString(dataToExport)); try { if (filename.Trim() != "" && filepath != "" && dtResult.Rows.Count != 0) { dataToExport.Append("<table width=\"100%\">"); dataToExport.Append("<tr>"); foreach (DataColumn dCol in dtResult.Columns) { dataToExport.Append("<td style=\"border:#ccc 1px dotted; height:40px; vertical-align:middle;text-align:center;min-width:100px; background-color:#D0EFF5;\">"); dataToExport.Append(HttpContext.Current.Server.HtmlEncode(dCol.ColumnName)); dataToExport.Append("</td>"); } dataToExport.Append("</tr>"); foreach (DataRow dRow in dtResult.Rows) { dataToExport.Append("<tr>"); foreach (object obj in dRow.ItemArray) { dataToExport.Append("<td style=\"border:#ccc 1px dotted;min-width:100px; vertical-align:middle;text-align:center;\">"); dataToExport.Append(HttpContext.Current.Server.HtmlEncode(obj.ToString())); dataToExport.Append("</td>"); } dataToExport.Append("</tr>"); } dataToExport.Append("</table>"); } sw.WriteLine(Convert.ToString(dataToExport)); sFlag = "Success"; sw.Close(); } catch (Exception ex) { throw ex; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)