您当前的位置: 首页 >  c#

彭世瑜

暂无认证

  • 1浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C#编程-121:文件保存之SaveFileDialog控件_彭世瑜_新浪博客

彭世瑜 发布时间:2017-08-14 22:21:52 ,浏览量:1

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. namespace SaveFileDialogTest
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void button1_Click(object sender, EventArgs e)
  20.         {
  21.             SaveFileDialog saveFile = new SaveFileDialog();
  22.             //saveFile.InitialDirectory = @"C:\";
  23.             saveFile.Filter = "文本文件|*.txt|97-2003Word文档|*.doc";
  24.             saveFile.FilterIndex = 1;
  25.             saveFile.FileName = "文本文件";
  26.             if (saveFile.ShowDialog() == DialogResult.OK)
  27.             {
  28.                 string fName = saveFile.FileName;
  29.                 FileStream fs = File.Open(fName, FileMode.Create);
  30.                 StreamWriter sw = new StreamWriter(fs);
  31.                 sw.Write(richTextBox1.Text);
  32.                 sw.Close();
  33.                 fs.Close();
  34.             }
  35.         }
  36.     }
  37. }
C#编程-121:文件保存之SaveFileDialog控件 C#编程-121:文件保存之SaveFileDialog控件
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.3826s