OpenFileDialog? or OpenDialog?OpenFileDialog dlg;
dlg = new OpenFileDialog();
dlg.Title = "打开文件";
dlg.Filter = "Windows Bitmap Files (*.bmp)|*.bmp|Windows JPG Files (*.jpg)|*.jpg" + "|All Files(*.*)|*.*";
if(dlg.ShowDialog() == DialogResult.OK)
{
try
{
文件名 = dlg.FileName; }
catch(Exception ee)
{
MessageBox.Show("Unable to load file: " + ee.Message);
}
}
dlg.Dispose();

解决方案 »

  1.   


    OpenFileDialog openFileDialog1 = new OpenFileDialog();
       if(openFileDialog1.ShowDialog() == DialogResult.OK)
        {
         openFileDialog1.FileName就是要用的文件名
        }
      

  2.   

    FileName包含了路径
    比如:“c:\test\aaa.exe"
    我只要aaa.exe
      

  3.   

    string str = filename;
    Path.GetFileName(str);
      

  4.   

    string filename = openFileDialog1.FileName 是文件完整路径名
    string filename_1Path.GetFileName(filename)是文件名