FolderbrowserDailog单击取消然后发生错误 [英] FolderbrowserDailog Click cancel then occurred Error

查看:75
本文介绍了FolderbrowserDailog单击取消然后发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我们点击btnfolderdailog然后选择文件然后点击Ok然后它的井。

如果我们点击取消按钮然后发生错误:-ArgumentException was未处理



路径不合法。









Hi,
If we click btnfolderdailog then select the file and click "Ok" then its well.
If we click cancel button then occurred Error:-ArgumentException was Unhandled

The path is not of a legal form.




folderBrowserDialog1.ShowDialog();

            totalfolderfileCount = System.IO.Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*").Length;
            string[] array = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.bdf*");
            txtInputPath.Text = folderBrowserDialog1.SelectedPath;

推荐答案

你调用ShowDialog,然后使用folderBrowserDialog1.SelectedPath属性。



你没有处理取消 - 你就好像一切都好。每当你在任何事情上调用ShowDialog时,你应该处理对话结果并根据结果工作。





You call ShowDialog and then use folderBrowserDialog1.SelectedPath property.

You didn't handle the canceling - you're just going as if everything is fine. Every time you call ShowDialog on anything, you should process dialog result and work depending on that result.


if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
    totalfolderfileCount = System.IO.Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*").Length;
            string[] array = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.bdf*");
            txtInputPath.Text = folderBrowserDialog1.SelectedPath;

}







如果这有帮助,请花时间接受解决方案,以便其他人可以找到它。谢谢。




If this helps, please take time to accept the solution so that others may find it. Thank you.


这篇关于FolderbrowserDailog单击取消然后发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆