if (ds.Tables[0].Rows.Count != 0)
{
for (i = 0; i < ds.Tables[0].Rows.Count; i++)
{
strFileContents = strFileContents + " " + ds.Tables[0].Rows[i]["UserName"] + " " + ds.Tables[0].Rows[i]["SearchDate"] + " " + ds.Tables[0].Rows[i]["Reference"] + " " + ds.Tables[0].Rows[i]["CaseType"] + " " + ds.Tables[0].Rows[i]["SearchName"] + " " + ds.Tables[0].Rows[i]["Location"] + System.Environment.NewLine;
}
Downloaded(strFileContents);
string strFilePath = "./downloads/filename.txt";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFilePath);
Response.WriteFile(strFilePath);
Response.End();
}
public void Downloaded(string strFileContents)
{
string strFilePath = Server.MapPath("./downloads/billing.txt").ToString();
if (!File.Exists(strFilePath))
{
File.Create(strFilePath).Close();
}
StreamWriter sw = File.CreateText(strFilePath);
sw.WriteLine(strFileContents);
sw.WriteLine(sw.NewLine);
sw.Flush();
sw.Close();
}