// 选择文件:
private string SelectPath()
{
string path = string.Empty;
var openFileDialog = new Microsoft.Win32.OpenFileDialog()
{
Filter = "Files (*.*)|*.*"//如果需要筛选txt文件("Files (*.txt)|*.txt")
};
var result = openFileDialog.ShowDialog();
if (result == true)
{
path = openFileDialog.FileName;
}
return path
}
// 选择路径
private string SelectPath()
{
string path = string.Empty;
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
path = fbd.SelectedPath;
}
return path;
}C# 选择文件路径,选择文件
最新推荐文章于 2025-09-12 10:58:54 发布
本文介绍了使用C#实现文件和目录选择的方法。通过两个不同的方法展示了如何让用户选择文件或目录,并获取其路径。
1325

被折叠的 条评论
为什么被折叠?



