有没有一种简单的方法来检查文件是否存在?我知道文件的名称不是扩展名.
所以对我来说,我可能是1. *
来自.jpg,.jpeg,.gif的任何内容. .png等用于图像格式.
if (System.IO.File.Exists("~/ProfilePictures/" + userID " + ".*")) { }
解决方法
使用
Directory.GetFiles
就像是:
var files = Directory.GetFiles("~/ProfilePictures/",userID + ".*"); if (files.length > 0) { // at least one matching file exists // file name is files[0] }