我正在尝试复制使用打开文件对话框工具选择的图像,但它一直抛出错误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);
}谢谢你的帮助!
发布于 2018-03-13 15:54:09
您需要定义CopyTo的完整路径
i.CopyTo(Path.Combine(@"C:\Users\Anthony\Documents", label1.Text, i.FileName));https://stackoverflow.com/questions/49250718
复制相似问题