Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi geeks,

I retrieve specific folder names in server. I've images for certain folder names with different formats(.jpg,.jpeg,.png) How to represent them ???

imgbtn.ImageUrl = "~/Images/" + d.Name+".jpg";

I need like this d.Name+".jpg/.jpeg/.png"

Pls someone help me
Posted

You can do the following.
C#
if (System.IO.File.Exists("~/Images/" + d.Name+".jpg"))
{
     imgbtn.ImageUrl = "~/Images/" + d.Name+".jpg";
}
else if (System.IO.File.Exists("~/Images/" + d.Name + ".jpeg"))
{
     imgbtn.ImageUrl = "~/Images/" + d.Name + ".jpeg";
}
else if (System.IO.File.Exists("~/Images/" + d.Name + ".png"))
{
     imgbtn.ImageUrl = "~/Images/" + d.Name + ".png";
}
 
Share this answer
 
ImageUrls must be to a specific file - which means a specific file name, including extension.

There is no mechanism for saying "one of these three possibilities, if any of them exist" - instead you will have to check for the file existance (File.Exists[^] will do it) to locate teh specific file, and then use the full URL for that.
 
Share this answer
 
Comments
Sriram Ramachandran 22-May-14 4:19am    
thanks ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900