C#编程-121:文件保存之SaveFileDialog控件

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace SaveFileDialogTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFile = new SaveFileDialog();
            //saveFile.InitialDirectory = @"C:\";
            saveFile.Filter = "文本文件|*.txt|97-2003Word文档|*.doc";
            saveFile.FilterIndex = 1;
            saveFile.FileName = "文本文件";
            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                string fName = saveFile.FileName;
                FileStream fs = File.Open(fName, FileMode.Create);
                StreamWriter sw = new StreamWriter(fs);
                sw.Write(richTextBox1.Text);
                sw.Close();
                fs.Close();
            }
        }
    }
}

C#编程-121:文件保存之SaveFileDialog控件C#编程-121:文件保存之SaveFileDialog控件

上一篇:零基础容器技术实战-学习报告


下一篇:云原生多模数据库 Lindorm助力东软集团 运维监控可视化