Thursday, August 06, 2009
Monday, August 03, 2009
C# ASP.NET use StringBuilder to export a txt file
StringBuilder strAAA = new StringBuilder();
foreach (DataRow drABC in datatableDEF.Rows)
{
strAAA.Append(drABC["xxxxx"]);
strAAA.Append(drABC[" "]);
strAAA.Append(drDEF["yyyyy"]);
strAAA.Append(drABC[" "]);
strAAA.Append(drGHI["zzzzzz"]);
strAAA.Append(drABC[" "]);
}
//end current line and start a new line
strAAA.AppendLine();
Response.AddHeader("content-disposition", "attachment;filename=ABC.txt"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.text"; StringWriter stringWrite = new StringWriter(); HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); Response.Write(strAAA.ToString()); Response.End();
Posted by SF at 11:30 am 0 comments
Subscribe to:
Posts (Atom)