https://zhidao.baidu.com/question/1765911607247226420.html
C#打开一个文件时获取目录下其他同类型文件的OpenFileDialog.filename并用数组保存。
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//DataTable dt = new NPOIExcelHelp().ReadExcelToTable(ofd.FileName);
bai string PathStr = Path.GetDirectoryName(ofd.FileName);//获取目录du
string Ext = Path.GetExtension(ofd.FileName);//获取扩展名zhi
string[] FileNames = Directory.GetFiles(PathStr);//获取所有文件
List<string> list = new List<string>();
foreach (string s in FileNames)
{
if (Path.GetExtension(s) == Ext)
{
list.Add(s);
}
}
}