OpenFileDialog openFile = new OpenFileDialog();
//仅仅显示:Excel文件类型
openFile.Filter = "(*.xls,*.xlsx)|*.xls;*.xlsx";
//不能文件多选
openFile.Multiselect = false;
//选择 Excel 文件
if (openFile.ShowDialog() == DialogResult.OK)
{
string pathName = openFile.FileName;
}
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Excel 工作簿(*.xls,*.xlsx)|*.xls;*.xlsx";
if (sfd.ShowDialog() == DialogResult.OK)
{
//文件路径和文件名称
string fileName = sfd.FileName.ToString();
}
FolderBrowserDialog path = new FolderBrowserDialog();
if (path.ShowDialog() == DialogResult.OK)
{
string path = path.SelectedPath;
}
filter 是过滤哪种文件格式。