C#文件选择和另存为

  • Post author:
  • Post category:其他


文件选择:

var openFileDialog = new OpenFileDialog();

openFileDialog.Filter = “Txt Files (

.txt)|

.txt”;

var result = openFileDialog.ShowDialog();

if (result == true)

{


try { m_Studentlist.Clear(); }

catch

{ }

startpath = openFileDialog.FileName;

string localFilePath = “”;

}

文件另存为:

SaveFileDialog saveFileDialog = new SaveFileDialog();

//设置文件类型

saveFileDialog.Filter = “Txt Files (

.txt)|

.txt”;

//保存对话框是否记忆上次打开的目录

saveFileDialog.RestoreDirectory = true;

var DialogResult = saveFileDialog.ShowDialog();

//点了保存按钮进入

if (DialogResult == true)

{


//获得文件路径

localFilePath = saveFileDialog.FileName.ToString();

}



版权声明:本文为qq_41441064原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。