1、SaveFileDialog
OpenFileDialog openfile = new OpenFileDialog(); //初始显示文件目录 //openfile.InitialDirectory = @""; openfile.Title = "请选择要发送的文件"; //过滤文件类型 openfile.Filter = "文本文件|*.txt|可执行文件|*.exe|STOCK|STOCK.txt|所有文件类型|*.*"; if (DialogResult.OK == openfile.ShowDialog()) { //将选择的文件的全路径赋值给文本框 textBox1.Text = openfile.FileName; }
2、SaveFileDialog
SaveFileDialog savefile = new SaveFileDialog(); //如果文件名未写后缀名则自动添加 *.*不会自动添加后缀名 savefile.AddExtension = true; savefile.Filter = "可执行文件|*.exe|文本文件|*.txt|STOCK|STOCK.txt|所有文件|*.*"; if(DialogResult.OK==savefile.ShowDialog()) { textBox1.Text = savefile.FileName; }