将数据网格视图中的一列导出到记事本(.txt)

Export one column in data grid view to notepad(.txt)
2021-11-25
  •  译文(汉语)
  •  原文(英语)

我的"下载按钮"上有此代码.是的,它会下载到记事本,但我想要的是当用户单击"下载按钮"时,会出现一个 SAVE-AS 文件对话框,可以保存和重命名文件.请帮忙!

   protected void btn_export_Click(object sender, EventArgs e)
    {
       TextWriter sw = new StreamWriter(@"C:\SumTotal\file11.txt");

        int rowcount = GridView1.Rows.Count;
        for (int i = 0; i < rowcount - 1; i++)
        {
            sw.WriteLine(GridView1.Rows[i].Cells[28].Text.ToString() + "\t");
        }
        sw.Close();     //Don't Forget Close the TextWriter Object(sw)
        Response.Write("Data Successfully Exported");
    }
解决过程1

你不能让浏览器显示一个它没有设置的文件对话框.您可以做的是添加一个文本框,用户可以在其中键入他们想要的文件名.进行另存为对话的唯一方法是使用 Flash 或 SilverLight.如果你觉得勇敢,或者一个 Java 小程序.

I have this code behind on my 'download button'. Yes, it downloads to notepad, but what i want is when the user clicks the 'download button', a SAVE-AS file dialogue will appear that can save and rename the file.please help!

   protected void btn_export_Click(object sender, EventArgs e)
    {
       TextWriter sw = new StreamWriter(@"C:\SumTotal\file11.txt");

        int rowcount = GridView1.Rows.Count;
        for (int i = 0; i < rowcount - 1; i++)
        {
            sw.WriteLine(GridView1.Rows[i].Cells[28].Text.ToString() + "\t");
        }
        sw.Close();     //Don't Forget Close the TextWriter Object(sw)
        Response.Write("Data Successfully Exported");
    }
Solutions1

You can't make the browser display a file dialogue it it's not set up to. What you CAN do is add a textbox where the user can type in the file name they want. The only way you can do a Save-as dialogue is by using Flash or SilverLight. Or a java applet if you're feeling brave.

转载于:https://stackoverflow.com/questions/15240637/export-one-column-in-data-grid-view-to-notepad-txt

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入