Click here to Skip to main content
11,647,828 members (59,743 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 26-Nov-12 0:16am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
}

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();
    }
  Permalink  

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

  Print Answers RSS
0 jyo.net 500
1 F-ES Sitecore 410
2 DamithSL 290
3 CPallini 290
4 OriginalGriff 277
0 OriginalGriff 1,342
1 jyo.net 994
2 DamithSL 971
3 Sergey Alexandrovich Kryukov 873
4 CPallini 845


Advertise | Privacy | Mobile
Web03 | 2.8.150804.4 | Last Updated 29 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100