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