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);//判断文件是否存在  
           }

 

 

 

posted @ 2016-10-22 09:40  DBing  阅读(8116)  评论(0)    收藏  举报