SAVING A FILE TO PROJECT FOLDER AND SAVE ITS PATH

Ida B Wells

Total Post:30

Points:210
Posted by  Ida B Wells
C# 
C#
 1273  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. ben reitman

    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

Answer

NEWSLETTER

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