C#将文件移动到文件夹

时间:2015-09-26 00:11:25

标签: c#

我收到错误“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();

如何解决?

1 个答案:

答案 0 :(得分:1)

在显示对话框之前设置onlyFileName,这意味着它为null(空),因此它不会被添加到您的路径中。