文件选择:
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();
}