Home > DeveloperSection > Forums > Saving a file to project folder and save its path
Ida B Wells
Ida B Wells

Total Post:30

Posted on    September-28-2013 8:52 AM

 C# C# 

 1 Reply(s)
 1207  View(s)
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?

ben reitman
ben reitman

Total Post:96

Posted on    September-28-2013 9:08 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick