//选择文件目录
private void btnSelectPath_Click(object sender, EventArgs e)
{
//创建对象
OpenFileDialog ofg = new OpenFileDialog();
//判断保存的路径是否存在
if (!Directory.Exists(@"D:\aaa"))
{
//创建路径
Directory.CreateDirectory(@"D:\aaa");
}
//设置默认打开路径(绝对路径)
ofg.InitialDirectory = @"D:\aaa";
//设置打开标题、后缀
ofg.Title = "请选择导入模板";
ofg.Filter = "mrt文件|*.mrt";
string path = "";
if (ofg.ShowDialog() == DialogResult.OK)
{
//得到打开的文件路径(包括文件名)
path = ofg.FileName.ToString();
this.txtLabelPath.Text = path; //赋值到文本框
}
else if (ofg.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("未选择打开文件!");
}
}