2014-03-06 136 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