【发布时间】:2013-02-22 14:29:42
【问题描述】:
我目前必须编写代码以允许我读取文件夹中的所有文件并将它们写入控制台。下面,我还获得了使用浏览器从目录中选择单个文件的代码。我想知道如何使用浏览按钮选择文件夹。
检查所有文件的代码
foreach(var path in Directory.GetFiles(@"C:\Name\Folder\"))
{
Console.WriteLine(path); // full path
Console.WriteLine(System.IO.Path.GetFileName(path)); // file name
}
打开对话框的代码
OpenFileDialog fileSelectPopUp = new OpenFileDialog();
fileSelectPopUp.Title = "";
fileSelectPopUp.InitialDirectory = @"c:\";
fileSelectPopUp.Filter = "All EXCEL FILES (*.xlsx*)|*.xlsx*|All files (*.*)|*.*";
fileSelectPopUp.FilterIndex = 2;
fileSelectPopUp.RestoreDirectory = true;
if (fileSelectPopUp.ShowDialog() == DialogResult.OK)
{
textBox1.Text = fileSelectPopUp.FileName;
}
【问题讨论】:
-
不知道这是否有帮助,但你可以试试stackoverflow.com/questions/31059/…
标签: c# file-upload