安然不哭-西坝阿超个人博客

做技术一定要一颗恒心,这样才不会半途而废。

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

2018-4-12 钟建超

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