您的位置:首页 > 编程语言 > C#

C# 选择文件 和 选择文件夹 对话框

2016-03-22 22:45 453 查看
<pre name="code" class="csharp">        private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog fileDialog = new OpenFileDialog();
fileDialog.Multiselect = true;
fileDialog.Title = "请选择文件";
fileDialog.Filter = "所有文件(*.*)|*.*";
if (fileDialog.ShowDialog() == DialogResult.OK)
{
string[] names = fileDialog.FileNames;

foreach(string file in names)
{
MessageBox.Show("已选择文件:" + file, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}
}

private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择文件路径";

if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SelectedPath;
DirectoryInfo theFolder = new DirectoryInfo(foldPath);
FileInfo[] dirInfo = theFolder.GetFiles();
//遍历文件夹
foreach (FileInfo file in dirInfo)
{
MessageBox.Show(file.ToString());
}
}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: