如何保存文件路径并在 C# windows 应用程序的浏览按钮中使用路径

How to save path of a file and use the path in browse button in C# windows application

在 C# windows 应用程序中,我有一个文本框 1 和 "create folder" 按钮以及 "Open created folder!" 按钮。 什么时候,我给 textbox1 命名,然后按 "create folder",用该名称创建一个文件夹。在下一步中,我想打开我创建的文件夹 问题是我不知道如何打开我创建的那个文件夹!我只能在我的文件夹名称之前打开一个目录。 如何获取 "create folder" 按钮中的路径并使用此路径打开文件夹内部? 这是我的代码:

        private void button1_Click(object sender, EventArgs e)
    {
        //create a folder

        var adr = System.IO.Directory.CreateDirectory(@"C:\Users\aa\Desktop\test2\" + textBox1.Text);

    }

    private void button2_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo()
        {
            FileName = (@"C:\Users\aa\Desktop\test2\"),
            UseShellExecute = true,
            Verb = "open"
        });

只需将文件夹的名称添加到您要打开的文件夹的路径中即可。

查涅这个:

FileName = (@"C:\Users\aa\Desktop\test2\")

为此:

FileName = (@"C:\Users\aa\Desktop\test2\" + textBox1.Text)