1

I open file as:

OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "JPG|*.jpg;*.jpeg|PNG|BMP|*.bmp|GIF|*.gif|*.png|TIFF|*.tif;*.tiff";

    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {

     //
    }

How can I save immediately this file in disc? I tried:

File.Copy(openFileDialog.FileName, @"C:\");
2
  • 2
    The second parameter to file copy needs to be the full path AND filename, not just the folder you want to copy it to - see this : msdn.microsoft.com/en-us/library/c6cfw35a(v=vs.110).aspx - you also need write permission to the folder you are saving to Commented Nov 2, 2016 at 16:12
  • 1
    Try File.Copy(openFileDialog.FileName, Path.Combine("C:\\", Path.GetFileName(openFileDialog.FileName))); Commented Nov 2, 2016 at 16:25

1 Answer 1

1

You need to give File.Copy() the absolute path, including the name of the file it's saving. "C:\" is not a valid file name, so it can't save it. Try something like:

string fName = "myPhoto";
File.Copy(openFileDialog.FileName, @"C:\" + fName + ".jpg");

Source: MSDN

PaulF also mentioned this in the comments prior to my posting this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.