WinForm下判断文件和文件夹是否存在

           //选择文件夹  
           FolderBrowserDialog dia = new FolderBrowserDialog();  
           if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
           {  
               string filePath = dia.SelectedPath;  
  
               Directory.Exists(filePath);//判断文件夹是否存在  
           }  
  
           //选择文件  
           OpenFileDialog dia = new OpenFileDialog();  
           if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
           {  
               string filePath = dia.SelectedPath;  
  
               File.Exists(filePath);//判断文件是否存在  
           }

原文地址:https://www.cnblogs.com/shenbing/p/5986734.html