无法使用文件打开对话框

解决方法:项目上右键,添加引用,选择System.Windows.Forms.dll。点确定。控制台程序默认不添加这个dll的。需要手工添加dll的引用。

代码中添加using System.Windows.Forms;的命名空间引用。

==========

OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = " PDF文件|*.PDF|所有文件|*.*";
ofd.ValidateNames = true;
ofd.CheckPathExists = true;
ofd.CheckFileExists = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
string strFileName = ofd.FileName;
return strFileName;
//其他代码
}

posted @ 2020-06-04 14:50  低调95  阅读(232)  评论(0)    收藏  举报