Dev
Dev

Reputation: 1073

How to save opened file in C#?

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:\");

Upvotes: 1

Views: 2112

Answers (1)

Lord Drake
Lord Drake

Reputation: 182

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.

Upvotes: 1

Related Questions