我使用的是 Visual Studio 2010 (c#)。
我想从我的计算机中选择一个 zip 或 rar 文件,将其保存到项目文件夹并将其路径存储到变量。
我尝试了openfiledialog()
,但我无法通过这种方式解决它。
我怎样才能做到这一点?
最佳答案
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);
}
}
您的文件将被复制到 yourprojectname\yourprojectname\bin\Debug
关于c# - 将文件保存到项目文件夹并保存其路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19067580/