C# 实现 打开资源管理器,选中文件,并上传

用C# 做个档案管理的软件,采用winform + DevExpress 。
现在需要个 “上传文件” 的页面, 打开资源管理器,选中文件后完成上传。如下图:

img


这个页面应该是调用系统的,C# 可以通过 ProcessStartInfo("Explorer.exe") 打开系统的资源管理器,但如何到达上图中的效果呢? (重点是下方的 “打开文件” 功能栏) 求教各位大佬

C# winform自带打开对话框,explorer则是win的资源管理器,跟打开没关系

string file ;
OpenFileDialog dialog = new OpenFileDialog();
dialog.Multiselect = true;//该值确定是否可以选择多个文件
dialog.Title = "打开";
dialog.Filter = "All File(*.*)|*.*";
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
    file = dialog.FileName; //获取到要打开的文件路径
}

具体可参考
https://docs.microsoft.com/zh-cn/dotnet/api/system.windows.forms.openfiledialog

如果你需要用户打开文件,可以使用OpenFileDialog,可以自己new,也可以从工具箱拖一个出来放窗体里
如果你需要用户保存文件,可以使用SaveFileDialog
如果你需要用户选文件夹,还有FolderBrowserDialog可以用


var fileContent = string.Empty;
var filePath = string.Empty;

using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
    openFileDialog.InitialDirectory = "c:\\";
    openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    openFileDialog.FilterIndex = 2;
    openFileDialog.RestoreDirectory = true;

    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
        //Get the path of specified file
        filePath = openFileDialog.FileName;

        //Read the contents of the file into a stream
        var fileStream = openFileDialog.OpenFile();

        using (StreamReader reader = new StreamReader(fileStream))
        {
            fileContent = reader.ReadToEnd();
        }
    }
}

MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);