打开文件、

using System.IO;

        string fileName;
        String extendedName;
        String fileName1;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();                //new一个方法
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); //定义打开的默认文件夹位置
            ofd.ShowDialog();          //显示打开文件的窗口
            fileName = ofd.FileName;                //获得选择的文件路径
            extendedName = Path.GetExtension(fileName);       //获得文件扩展名
            fileName1 = Path.GetFileName(fileName);
        }

原文地址:https://www.cnblogs.com/taikongbai/p/3578683.html