如何将数据集中的数据导出到Web应用程序中的记事本 [英] How to export the data in the dataset to notepad in web application

查看:81
本文介绍了如何将数据集中的数据导出到Web应用程序中的记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我使用的是VS 2005,adp.net,c#.net。

我有一个网络应用程序。

如何将数据集中的数据导出到客户端系统中的记事本?



提前付款



george

解决方案

我认为你可以把你的数据转储到网页上,所有这些都是格式化的(当然你可能需要在你的脚本) - 用于审查,然后使用document.exec命令和IDM_SaveAs(?)保存显示的数据(意思是网页)



我不记得了它使用它已经很久了,



但你可以找到更多信息这里



最后我使用它是在IE6中,但调用语法略有不同,当我在寻找如何添加添加到收藏夹按钮时,我才发现它,并注意到它非常相似ar。


protected void btn_Download_Click(object sender,EventArgs e)

{

DataSet ds = new DataSet();

ds = GetDatatable();

string filename =MyObCustomerCard.txt;

//将数据导出到文本文件

ExportDataTabletoFile(ds.Tables [0],,true,Server.MapPath(〜/ image / MyObCustomerCard.txt));

#region下载记事本或文本文件。 />
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

}



<前郎=cs> public void ExportDataTabletoFile(DataTable datatable, string 分隔, bool exportcolumnsheader, string file)
{
StreamWriter str = new StreamWriter(file, false ,System.Text.Encoding.Default);
if (exportcolumnsheader)
{
string Columns = .Empty;
foreach (DataColumn column in datatable.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();
}


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

解决方案

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.


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


这篇关于如何将数据集中的数据导出到Web应用程序中的记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆