using System.IO
public void SaveFile()
        {
            //实例化一个保存文件对话框
            SaveFileDialog sf = new SaveFileDialog();
            //设置文件保存类型
            sf.Filter = "txt文件|*.txt|xml";
            //如果用户没有输入扩展名,自动追加后缀
            sf.AddExtension = true;
            //设置标题
            sf.Title = "写文件";
            //如果用户点击了保存按钮
            if (sf.ShowDialog() == DialogResult.OK)
            {
                //实例化一个文件流--->与写入文件相关联
                FileStream fs = new FileStream(sf.FileName, FileMode.Create);
                //实例化一个StreamWriter-->与fs相关联
                StreamWriter sw = new StreamWriter(fs);
                //开始写入
                if (this.dataGridView1.Rows.Count < 1)
                {
                    MessageBox.Show("没有数据!导出失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
                else
                {
                    for (int i = 0; i < this.dataGridView1.Rows.Count - 1; i  )
                    {
                        sw.WriteLine(this.dataGridView1.Rows[i].Cells[0].Value.ToString());
                    }
                    //sw.Write(this.textBox1.Text);
                    //清空缓冲区
                    sw.Flush();
                    //关闭流
                    sw.Close();
                    fs.Close();
                    MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

最新文章

  1. js深浅复制
  2. Spring-IOC-BeanFactory
  3. js实现身份证号码验证
  4. Cheatsheet: 2014 01.01 ~ 01.14
  5. REST架构实质(转)
  6. 关于VS2010error RC2170 : bitmap file res\tmp1.bmp is not in 3.00 format
  7. https,https的本地测试环境搭建,asp.net结合https的代码实现,http网站转换成https网站之后遇到的问题
  8. OpenJudge 2815 城堡问题 / Poj 1164 The Castle
  9. Tomcat启动load action异常
  10. 基于visual Studio2013解决面试题之0206hash表实现
  11. 分页。php 引用代码
  12. ES6 继续 变量的解构赋值
  13. Centos7安装JStorm2.1.1
  14. 关于eclipse的一些问题
  15. 软件工程第三周的学习报告 html&lt;input&gt; final finally finalize 的比较 BigInteger
  16. 利用RTL2832u电视棒芯片追踪民航飞机轨迹
  17. 存储过程 传 datatable
  18. [Java 泥水匠] Java Components 之一:Java String (肯定有你不懂的)
  19. Java插件之Jrebel
  20. Django多个中间件的执行顺序

热门文章

  1. 自制的几个jquery插件
  2. php-fpm 启动 关闭 进程逃逸 pid
  3. Oracle学习笔记—Oracle左连接、右连接、全外连接以及(+)号用法(转载)
  4. springMVC中使用 RequestBody 及 Ajax POST请求 415 (Unsupported Media Type)
  5. LeetCode:螺旋矩阵||【59】
  6. list列表、tuple元组、range常用方法总结
  7. 防止基本的XSS攻击 滤掉HTML标签
  8. token的生成和应用
  9. Linux虚拟内存管理(glibc)
  10. 20145222黄亚奇 《网络对抗技术》 MAL_逆向与Bof基础