.net c# 选择文件可使用 OpenFileDialog 控件
private void zbtnfile_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = true; //该值确定是否可以选择多个文件
dialog.Title = "UF请选择文件"; //弹窗的标题
dialog.InitialDirectory = "D:\\"; //默认打开的文件夹的位置
dialog.Filter = "MicroSoft Excel文件(*.xlsx)|*.xlsx|所有文件(*.*)|*.*"; //筛选文件
dialog.FilterIndex = 2; //指定筛选默认索引
dialog.ShowHelp = false; //是否显示“帮助”按钮
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
ztxtfile.Text = dialog.FileName;
}
}
文件夹选择器: FolderBrowserDialog 类
private void zbtnfolder_Click(object sender, EventArgs e)
{
FolderBrowserDialog folder = new FolderBrowserDialog();
folder.Description = "选择文件所在文件夹目录"; //提示的文字
if (folder.ShowDialog() == DialogResult.OK)
{
ztxtfolder.Text = folder.SelectedPath;
}
}