2014-03-06 129 views
-3

I使用Windows Phone 8应用程序。检查图像资源是否为空

string Image = "/MyData/" + myObject.ImageName + "big.png"; 
BitmapImage bmp = new BitmapImage(new Uri(Image , UriKind.Relative)); 

       MyImage.Source = bmp; 

我的文件夹中的图像迈德特/,我有2套图像像<imagename>big.png,<imagename>small.png.

因此,这里所发生的事情是我想检查是否存在于位置<imagename>big.png与否,如果不挑<imagename>small.png.

如何做到这一点?

编辑

我解决了它自己,这里是如何。

File.Exists("path to file") here path should be `folderName/filenames` and not `/folderName/filenames` 

感谢所有帮助过我的人。

+0

为什么要downvote?这个问题有什么不对? – user3114009

+0

你有没有试过File.Exists方法? –

+0

@JagathMurali是的,我试过了,它不工作, – user3114009

回答

0
string image = "/MyData/" + myObject.ImageName + "/big.png"; 
string fileName = Path.GetFileName(image); 
if(!string.IsNullOrEmpty(fileName)) 
{ 
MessageBox.Show("File Exist -"+fileName); 
} 
else 
{ 
MessageBox.Show("No File Exist -"); 
} 
BitmapImage bmp = new BitmapImage(new Uri(image , UriKind.Relative)); 
if(bmp==null) 
{ 
image = "/MyData/" + myObject.ImageName + "/small.png"; 
bmp = new BitmapImage(new Uri(image , UriKind.Relative)); 
} 
MyImage.Source = bmp; 
+0

不工作,我也试过,以及 – user3114009

+0

我在我的答案编辑。看一看 – Jaihind

+0

有什么变化? – user3114009