Check if image file exists before linking to Image object

Discussion in 'ASP .Net Web Controls' started by Filip De Backer, Jun 11, 2004.

  1. 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
    Filip De Backer, Jun 11, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski

    Making sure a file exists before uploading it

    Nathan Sokalski, Aug 21, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    1,632
    Chris Dunaway
    Aug 22, 2005
  2. Totan
    Replies:
    0
    Views:
    937
    Totan
    Apr 17, 2006
  3. Jason Stacy
    Replies:
    2
    Views:
    4,683
    Roedy Green
    Apr 27, 2008
  4. Ulf Meinhardt
    Replies:
    8
    Views:
    6,141
  5. Filip De Backer

    check if image or file exists

    Filip De Backer, Jun 22, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    266
    oraclevsmicrosoft
    Jun 23, 2005
Loading...

Share This Page