Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想用 OpenFileDialog 打开 2 种类型的文件(.txt 和 .dat),每种类型的文件都应该用不同的算法打开。OpenFile 方法获取我正在打开的文件的流。但是,我能得到那个文件的类型吗?还是有另一种区分文件的方法?
如果我们谈论winforms,那么您有可用的文件名,您可以在打开文件之前检查扩展名..
var dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { var extension = Path.GetExtension(dialog.FileName); // do what you need }