方法很多但都要使用 System.IO 命名空间
给你两个做参考:
//======== 1. 方法一(要使用存在的文件信息) =======
FileInfo file = new FileInfo(sFilePath);
if (file.Exists)
{
//文件存在
string sName = file.Name;
}
else
{
//文件不存在
}
//======== 2. 方法二(只要判断文件的存在性) =======
if (File.Exists(sFilePath))
{
//文件存在
}
else
{
//文件不存在
}
可以使用如下代码进行判断
string filepath =@"D:\dd.jpg";
if (System.IO.File.Exists(filepath))
{
MessageBox.Show("存在");
}
else
{
MessageBox.Show("不存在");
}
System.IO.File.Exists
这个方法就可以