string ConnectionString = "server=localhost;database=xyz;Integrated Security=True";
string cadenanombre = "";
SqlConnection cn
= new SqlConnection
(ConnectionString
); SqlCommand Command
= new SqlCommand
("select * from ....", cn
); cn.Open();
DataSet ds
= new DataSet
(); SqlDataAdapter ad
= new SqlDataAdapter
(Command
); ad.Fill(ds);
StringBuilder str
= new StringBuilder
();
for (int i = 0; i < ds.Tables[0].Rows.Count ; i++)
{
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
{
cadenanombre=ds.Tables[0].Rows[i][j + 1].ToString();
str.Append(cadenanombre);
}
}
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();
cn.Close();
cn.Dispose();