Saving a file to project folder and save its path

Total Post:30

Points:210
C# 
C#
 1572  View(s)
Ratings:
Rate this:

I am using visual studio 2010 (c#).

I would like to select a zip or rar file from my computer, save it to project folder and store its path to a variable.

I tried openfiledialog() but I couldn't solve it this way.

How can I do that?

  1. Post:96

    Points:676
    Re: Saving a file to project folder and save its path

    Hey Ida!

    private void button1_Click(object sender, EventArgs e)
            {
                 var openFileDialog=new OpenFileDialog {Filter = @"Zip Files|*.zip|RAR Files|*.rar|All Files|*.*"};
                if (DialogResult.OK == openFileDialog.ShowDialog())
                {
                    File.Copy(openFileDialog.FileName, Application.StartupPath + @"\"
                        + Path.GetFileName(openFileDialog.FileName));
                    yourvariable = Application.StartupPath + @"\"
                                   + Path.GetFileName(openFileDialog.FileName);
                }
            }


    your file will be copied to yourprojectname\yourprojectname\bin\Debug

      Modified On Mar-31-2018 04:23:01 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!