public void Save_stringBuilder()
{
StringBuilder
sb = new StringBuilder();
sb.Append("<table
border='1' width='800' align='center'
style='text-align:center'><tr><td colspan='3' style='
background-color:#000; height:100; color:#fff;
font-size:x-large'>Header</td></tr><tr><td height='100'
align='center'><img
src='C:\\Users\\Krishna\\Desktop\\SaveGridViewAsExcelOnDisk\\a.gif' width='70'
height='80'> </td><td> </td><td><img
src='C:\\Users\\Krishna\\Desktop\\SaveGridViewAsExcelOnDisk\\b.gif' width='70'
height='80'></td></tr><tr><td>&asldkfj;laksjdk
fj;k as
askdjflajksdf;</td><td> </td><td> </td></tr><tr><td> </td><td>&asdkf;ajsdlkfj
asdjfljasd faskldjflkas;</td><td> </td></tr><tr><td> </td><td> </td><td> </td></tr><tr><td>&asdkjfflkasjd
aksdjfl;jalsd skjdflkkjasd
fas;</td><td> </td><td> </td></tr><tr><td> </td><td> </td><td> </td></tr><tr><td> </td><td height='100' align='center'><img
src='C:\\Users\\Krishna\\Desktop\\SaveGridViewAsExcelOnDisk\\b.gif' width='70'
height='80' />
</td><td> </td></tr></table>");
string
path = Server.MapPath("~/Files/");
if (!Directory.Exists(path)) // create folder if not exist
{
Directory.CreateDirectory(path);
}
using (StringWriter sw = new
StringWriter(sb))
{
using
(HtmlTextWriter hw = new HtmlTextWriter(sw))
{
StreamWriter
writer = File.AppendText(path + "SavestringBuilder.xls");
hw.BeginRender();
string
html = sb.ToString();
writer.WriteLine(html);// write file on server folder
writer.Close();
}
}
}