C#打开文件对话框

OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = System.Environment.CurrentDirectory;//设定默认打开路径
if (ofd.ShowDialog() == DialogResult.OK)
{
    string filePathName = ofd.FileName;
    string fileName = Path.GetFileName(filePathName);  //文件名
    string extension = Path.GetExtension(fileName);   //扩展名
    string filePath = Path.GetDirectoryName(filePathName);
}
原文地址:https://www.cnblogs.com/xieqianli/p/5126159.html