Reputation: 69
I am trying to copy an image that was selected using the open file dialog tool, but it keeps throwing me the error
System.IO.IOException: 'The target file "C:\Users\Anthony\Documents\\yes" is a directory, not a file.'
.
This is my code for that section.
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);
}
Thanks for the help!
Upvotes: 0
Views: 2224
Reputation: 2768
You need to define the full path for CopyTo
i.CopyTo(Path.Combine(@"C:\Users\Anthony\Documents", label1.Text, i.FileName));
Upvotes: 1