Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,

I am using VS 2005 ,adp.net,c#.net.
I have a web application.
How to export the data in the dataset to notepad in client system?

Thanks in advance

george
Posted

I think you can dump your data to the web page all nicely formatted off course in columns (which you may have to in your script) - for review and then save the data that is displayed (meaning the webpage) using the document.exec command and the IDM_SaveAs (?)

I cannot remember its been so long since i used it,

but you can find more info Here

Last i used it was in IE6 but the calling syntax was slightly different and i only came across it when i was looking for how to add an add to favorites button and noticed it was very similar.
 
Share this answer
 
protected void btn_Download_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds = GetDatatable();
string filename = "MyObCustomerCard.txt";
// Exporting Data to text file
ExportDataTabletoFile(ds.Tables[0], " ", true, Server.MapPath("~/image/MyObCustomerCard.txt"));
#region download notepad or text file.
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/contents/" + filename);
Response.TransmitFile(Server.MapPath("~/image/" + filename));
HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();
#endregion
}

C#
public void ExportDataTabletoFile(DataTable datatable, string delimited, bool exportcolumnsheader, string file)
    {
        StreamWriter str = new StreamWriter(file, false, System.Text.Encoding.Default);
        if (exportcolumnsheader)
        {
            string Columns = string.Empty;
            foreach (DataColumn column in datatable.Columns)
            {
                Columns += column.ColumnName + delimited;
            }
            str.WriteLine(Columns.Remove(Columns.Length - 1, 1));
        }
        foreach (DataRow datarow in datatable.Rows)
        {
            string row = string.Empty;
            foreach (object items in datarow.ItemArray)
            {
                row += items.ToString() + delimited;
            }
            str.WriteLine(row.Remove(row.Length - 1, 1));
        }
        str.Flush();
        str.Close();
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900