我正在尝试复制使用打开文件对话框工具选择的图像,但它一直在向我提出错误
System.IO.IOException: 'The target file "C:\Users\Anthony\Documents\\yes" is a directory, not a file.'
。
这是该部分的代码。
private void button2_Click_1(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select Background Image";
ofd.Filter = "Image Files(*.jpg; *.jpeg; *.png;)|*.jpg; *.jpeg; *.png;";
ofd.InitialDirectory = @"C:\";
if (ofd.ShowDialog() == DialogResult.OK)
{
label15.Text = ofd.FileName;
FileInfo i = new FileInfo(ofd.FileName);
i.CopyTo(@"C:\Users\Anthony\Documents\\" + label1.Text);
}
感谢您的帮助!
答案 0 :(得分:1)
您需要定义CopyTo
i.CopyTo(Path.Combine(@"C:\Users\Anthony\Documents", label1.Text, i.FileName));