【问题标题】:Detect if Image Exists with File.Exists使用 File.Exists 检测图像是否存在
【发布时间】:2016-05-29 16:38:33
【问题描述】:

我尝试检测图像是否存在但无法正常工作。如果退出则需要加载图像,如果不退出则需要加载默认图像。 IF/ELSE 工作只是第一部分没有,我做错了什么我一直得到默认图像

@{ String imageURL = "http://www.XXXX.com/cdcover.jpg')"; 
}
@if (File.Exists(imageURL)) {
    @section cdcover{ src="http://www.XXXX.com/cd/XX/cdcover.jpg")" }
    }
else { 
    @section cdcover{ src="http://www.XXXX.com/cd/defaulcover.jpg" }   
    }

【问题讨论】:

标签: javascript c# html


【解决方案1】:

这是一个概念:

var bitmapImage = new BitmapImage(); // An image var
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri("/*image url*/");; // set a value to our var
bitmapImage.EndInit(); img.Source = bitmapImage;

if (File.Exists(bitmapImage)){ // checks if the var has an existing image
//code

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    • 1970-01-01
    • 2014-01-16
    • 2015-10-20
    • 2023-03-24
    • 1970-01-01
    • 2018-04-04
    相关资源
    最近更新 更多