C# 选择文件路径,选择文件


// 选择文件:
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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM