Check if image file exists before linking to Image object

F

Filip De Backer

Hi,

I know that the File object doens't work in asp.net, but how can I check if a file MyDog.jpg exists before I link it to the Image object in my web aplication.
I want to show NoPicture.jpg when the file doesn't exist.

I want to change the code to something I can use but I don't know what :

strFileName = "MyDog.jpg";
if (System.IO.File.Exists(strFileName))
{
imgPicture1.ImageUrl = strFileName;
}
else
{
imgPicture1.ImageUrl = "NoPicture.jpg";
}

thanks a lot

Filip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top