在文件浏览器中选择了错误的文件夹时ArgumentOutOfRangeException

时间:2017-04-17 23:41:59

标签: c# wpf

所以我在WPF C#中开发了一些东西。它首先浏览文件以使系统正常工作。但是,如果所选文件夹位于错误的文件中,则会抛出错误

  

类型' System.ArgumentOutOfRangeException'的例外情况发生在mscorlib.dll中但未在用户代码中处理

var browse = new System.Windows.Forms.FolderBrowserDialog();
browse.Description = "Select a folder containing *.train files.";
if (browse.ShowDialog() != System.Windows.Forms.DialogResult.OK)
    return;
string[] fileNames = Directory.GetFiles(browse.SelectedPath, "*.train");           
Array.Sort(fileNames);

提前谢谢!

1 个答案:

答案 0 :(得分:0)

   var browse = new System.Windows.Forms.FolderBrowserDialog();
    browse.Description = "Select a folder containing *.train files.";
    if (browse.ShowDialog() != System.Windows.Forms.DialogResult.OK)
        return;
    if (!string.IsNullOrEmpty(browse.SelectedPath))
    {
        string[] fileNames = Directory.GetFiles(browse.SelectedPath, "*.train"); 
        Array.Sort(fileNames);
    }