Export the datagrid data to text in asp.net
Posted
by SRIRAM
on Stack Overflow
See other posts from Stack Overflow
or by SRIRAM
Published on 2009-10-06T06:40:00Z
Indexed on
2010/03/21
6:11 UTC
Read the original article
Hit count: 526
Problem:It will asks there is no assembly reference/namespace for Database
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper selectCommandWrapper =
db.GetStoredProcCommandWrapper("sp_GetLatestArticles");
DataSet ds = db.ExecuteDataSet(selectCommandWrapper);
StringBuilder str = new StringBuilder();
for(int i=0;i<=ds.Tables[0].Rows.Count - 1; i++)
{
for(int j=0;j<=ds.Tables[0].Columns.Count - 1; j++)
{
str.Append(ds.Tables[0].Rows[i][j].ToString());
}
str.Append("<BR>");
}
Response.Clear();
Response.AddHeader("content-disposition",
"attachment;filename=FileName.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);
Response.Write(str.ToString());
Response.End();
© Stack Overflow or respective owner