C#Winform判断文件和路径是否存在

Posted DBing

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#Winform判断文件和路径是否存在相关的知识,希望对你有一定的参考价值。

  1.            //选择文件夹  
  2.            FolderBrowserDialog dia = new FolderBrowserDialog();  
  3.            if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
  4.            {  
  5.                string filePath = dia.SelectedPath;  
  6.   
  7.                Directory.Exists(filePath);//判断文件夹是否存在  
  8.            }  
  9.   
  10.            //选择文件  
  11.            OpenFileDialog dia = new OpenFileDialog();  
  12.            if (dia.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
  13.            {  
  14.                string filePath = dia.SelectedPath;  
  15.   
  16.                File.Exists(filePath);//判断文件是否存在  
  17.            }

以上是关于C#Winform判断文件和路径是否存在的主要内容,如果未能解决你的问题,请参考以下文章