我收到错误“Extensions”是一个文件夹,而不是文件,在尝试运行时
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "MSL Files (.MSL)|*.MSL";
var onlyFileName = System.IO.Path.GetFileName(openFileDialog.FileName);
bool flag = openFileDialog.ShowDialog() == DialogResult.OK;
if (flag)
{
this.txtPath.Text = openFileDialog.FileName;
File.Copy(txtPath.Text, Application.StartupPath + @"\Extensions\" + @onlyFileName);
}
extensionTree.Refresh();
如何解决?
答案 0 :(得分:1)
在显示对话框之前设置onlyFileName,这意味着它为null(空),因此它不会被添加到您的路径中。