IF exist /w FSO

Discussion in 'ASP General' started by EQNish, May 16, 2008.

  1. EQNish

    EQNish Guest

    IS there a way I can do an If exist to determin if a graphic is displayed?

    something like this;


    <p align="center">

    if file exist "fileone.jpg"
    <img border="0" src="fileone.jpg">
    if File exist "filetwo.jpg"
    <img border="0" src="fileone.jpg">
    </p>


    What I am trying to do is post JPGs from a folder structure, the files may
    or maynot be there, but I don't want to have the blank picture reference to
    be displayed as if I where to just hard code the graphics in the Html!
     
    EQNish, May 16, 2008
    #1
    1. Advertising

  2. "EQNish" <> wrote in message
    news:...
    > IS there a way I can do an If exist to determin if a graphic is displayed?
    >
    > something like this;
    >
    >
    > <p align="center">
    >
    > if file exist "fileone.jpg"
    > <img border="0" src="fileone.jpg">
    > if File exist "filetwo.jpg"
    > <img border="0" src="fileone.jpg">
    > </p>
    >
    >
    > What I am trying to do is post JPGs from a folder structure, the files may
    > or maynot be there, but I don't want to have the blank picture reference

    to
    > be displayed as if I where to just hard code the graphics in the Html!
    >


    Try this (warning air code):-

    <%

    Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

    Dim fileNames
    fileNames= Array("fileone.jpg", "filetwo.jpg") 'Note these are URL paths

    %>


    <p align="center">
    <%

    Dim fileName
    For Each fileName in fileNames
    If fso.FileExists(Server.MapPath(fileName)) Then
    %>
    <img border="0" src="<%=fileName%>" />
    <%
    End If
    Next
    %>
    </p>


    --
    Anthony Jones - MVP ASP/ASP.NET
     
    Anthony Jones, May 16, 2008
    #2
    1. Advertising

  3. EQNish

    Evertjan. Guest

    Anthony Jones wrote on 16 mei 2008 in
    microsoft.public.inetserver.asp.general:

    > "EQNish" <> wrote in message
    > news:...
    >> IS there a way I can do an If exist to determin if a graphic is
    >> displayed?
    >>
    >> something like this;
    >>
    >>
    >> <p align="center">
    >>
    >> if file exist "fileone.jpg"
    >> <img border="0" src="fileone.jpg">
    >> if File exist "filetwo.jpg"
    >> <img border="0" src="fileone.jpg">
    >> </p>
    >>
    >>
    >> What I am trying to do is post JPGs from a folder structure, the
    >> files may or maynot be there, but I don't want to have the blank
    >> picture reference

    > to
    >> be displayed as if I where to just hard code the graphics in the
    >> Html!
    >>

    >
    > Try this (warning air code):-
    >
    > <%
    >
    > Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    >
    > Dim fileNames
    > fileNames= Array("fileone.jpg", "filetwo.jpg") 'Note these are URL
    > paths
    >
    > %>
    >
    >
    > <p align="center">
    > <%
    >
    > Dim fileName
    > For Each fileName in fileNames
    > If fso.FileExists(Server.MapPath(fileName)) Then
    > %>
    > <img border="0" src="<%=fileName%>" />
    > <%
    > End If
    > Next
    > %>
    > </p>


    Or you can send a default I'm-sorry-image by dedicated 404.asp, having:

    qstr = lcase(Request.ServerVariables("QUERY_STRING"))
    if right(qstr,4)=".jpg" or right(qstr,4)=".gif" then
    response.redirect "/special/404.jpg"
    end if

    [make sure /special/404.jpg exists]


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., May 16, 2008
    #3
    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. Y.S.
    Replies:
    3
    Views:
    1,046
    strajan
    Sep 17, 2003
  2. LT
    Replies:
    7
    Views:
    2,112
    Phlip
    Jul 25, 2004
  3. KEN

    ASP FSO File Name Problem

    KEN, Jul 25, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    422
    Peter Bucher [MVP]
    Jul 26, 2007
  4. NIck
    Replies:
    0
    Views:
    119
  5. Markus Mohr
    Replies:
    7
    Views:
    261
    Thomas 'PointedEars' Lahn
    Nov 28, 2003
Loading...

Share This Page