www.webdeveloper.com
Results 1 to 4 of 4

Thread: Check to See If File Exists

  1. #1
    Join Date
    Oct 2013
    Posts
    4

    Check to See If File Exists

    I posted this in a wrong forum yesterday and I think I was asking the wrong question so here goes again:

    I have a situation where as part of a product purchase we need to enable customers to download a .pdf file as part of the purchase. Sometimes though the file is a .zip so I want the page to check to see if there is a .zip file with that product code (if the product code is abc1234, the pdf would be doc_abc123.pdf and the zip might be materials_abc123.zip with the "abc123" being a variable).

    I tried using the FileExists method but something is off with my syntax and I am not sure how to make it work.

    <%
    dim fs
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    if fs.FileExists("http://domain/folder/materials_<%= displayProductCode %>.zip") then
    <a href="http://domain/folder/materials_<%= displayProductCode %>.zip" target="_blank"><img src="images/download_handbook_btn.png" alt="Download Handbook" /></a>&nbsp;
    else
    <a href="http://domain/folder/handbook_<%= displayProductCode %>.pdf" target="_blank"><img src="images/download_handbook_btn.png" alt="Download Handbook" /></a>&nbsp;
    end if
    set fs=nothing
    %>


    It does not seems to like the ending ASP tag after the first <%= displayProductCode %>.

    Can someone help me out with this?

    Thanks in advance.

    Scott

  2. #2
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    You can't embed ASP tags

    <%
    dim fs
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    if fs.FileExists("http://domain/folder/materials_<%= displayProductCode %>.zip") then
    <a href="http://domain/folder/materials_<%= displayProductCode %>.zip" target="_blank"><img src="images/download_handbook_btn.png" alt="Download Handbook" /></a>&nbsp;
    else
    <a href="http://domain/folder/handbook_<%= displayProductCode %>.pdf" target="_blank"><img src="images/download_handbook_btn.png" alt="Download Handbook" /></a>&nbsp;
    end if
    set fs=nothing
    %>


    should be


    <%
    dim fs
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    if fs.FileExists("http://domain/folder/materials_"& displayProductCode &".zip") then
    response.write"<a href=""http://domain/folder/materials_"& displayProductCode &".zip"" target=""_blank""><img src=""images/download_handbook_btn.png"" alt=""Download Handbook"" /></a>&nbsp;"
    else
    response.write"<a href=""http://domain/folder/handbook_"& displayProductCode &".pdf"" target=""_blank""><img src=""images/download_handbook_btn.png"" alt=""Download Handbook"" /></a>&nbsp;"
    end if
    set fs=nothing
    %>

  3. #3
    Join Date
    Oct 2013
    Posts
    4
    Thanks.

    For some reason my condition is not being met. I have uploaded the .zip file but it will only display the link to the .pdf file. I changed the extension from .pdf to .zip in the else statement and then it displayed the link to the .zip file which is what lead me to believe the condition is not being met. I even tried changing the condition to look directly at the file in question instead of looking for ' materials_"& displayProductCode &".zip" '.

    Any thoughts?

    Thanks in advance.

    Scott

    Quote Originally Posted by yamaharuss View Post
    You can't embed ASP tags

    <%
    dim fs
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    if fs.FileExists("http://domain/folder/materials_<%= displayProductCode %>.zip") then
    <a href="http://domain/folder/materials_<%= displayProductCode %>.zip" target="_blank"><img src="images/download_handbook_btn.png" alt="Download Handbook" /></a>&nbsp;
    else
    <a href="http://domain/folder/handbook_<%= displayProductCode %>.pdf" target="_blank"><img src="images/download_handbook_btn.png" alt="Download Handbook" /></a>&nbsp;
    end if
    set fs=nothing
    %>


    should be


    <%
    dim fs
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    if fs.FileExists("http://domain/folder/materials_"& displayProductCode &".zip") then
    response.write"<a href=""http://domain/folder/materials_"& displayProductCode &".zip"" target=""_blank""><img src=""images/download_handbook_btn.png"" alt=""Download Handbook"" /></a>&nbsp;"
    else
    response.write"<a href=""http://domain/folder/handbook_"& displayProductCode &".pdf"" target=""_blank""><img src=""images/download_handbook_btn.png"" alt=""Download Handbook"" /></a>&nbsp;"
    end if
    set fs=nothing
    %>

  4. #4
    Join Date
    Oct 2013
    Posts
    4
    Nevermind - I figured it out.

    I created a path variable and then used that variable in my condition statement.

Thread Information

Users Browsing this Thread

There are currently 8 users browsing this thread. (0 members and 8 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles