C# gui点击按键选择对应文件夹遍历.xml文件

想用C#实现以下功能。

  1. 在GUI上编辑一个新的按键,目前我已经有GUI 界面。点击这个按键,弹出对话框,我可以在对话框中选中对应的文件夹,(目前不知道怎么选中文件夹)然后系统遍历文件夹中所有的.xml文件,文件夹包括一级文件夹,二级文件夹。要求遍历.xml后,可以知道每个.xml文件的具体地址。最好是在console里打印出来对应地址?
    遍历可以用这个命令
string[] xmlfiles = System.IO.Directory.GetFiles(@"F:\CSharp", "*.xml", SearchOption.AllDirectories);


private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            dialog.Description = "请选择文件路径";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string foldPath = dialog.SelectedPath;
                this.textBox1.Text = foldPath;

                string[] files = Directory.GetFiles(foldPath, "*.xml", SearchOption.AllDirectories);

                this.listBox1.Items.AddRange(files);

                foreach (var file in files)
                {
                    //file为每个xml文件的具体路径
                }
            }
        }

链接: 百度网盘 请输入提取码 百度网盘为您提供文件的网络备份、同步和分享服务。空间大、速度快、安全稳固,支持教育网加速,支持手机端。注册使用百度网盘即可享受免费存储空间 https://pan.baidu.com/s/1TGdNBxtt0gbvce1vWFX01Q
提取码:vsxj
--来自百度网盘超级会员V4的分享

工具箱--对话框--FolderBroswerDialog,拖入窗体

void func()
{
if(folderBroswer1.ShowDialog == DialogResult.OK)
{
string folder = folderBrowserDialog1.SelectedPath;
string[] xmlfiles = System.IO.Directory.GetFiles(folder , "*.xml", SearchOption.AllDirectories);
}
}

你不是窗体吗?怎么在console里输出?

soeasy 需要call