1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Ignore included file not found and show the rest of the page, not error?

Discussion in 'C#' started by Error404, May 8, 2009.

  1. #1
    Hi there,

    I have page I created.. and this is one part of its code...

    <!--#include file="sms1.txt"-->
    <!--#include file="sms2.txt"-->
    <!--#include file="sms3.txt"-->
    <!--#include file="sms4.txt"-->
    <!--#include file="sms5.txt"-->
    Code (markup):
    etc...

    So this are just plain txt files that I want to include on my page, right..



    Now the thing is, not all of these txt files are always on server, and that is ok to be... So for example I can sometimes have situation where file sms4.txt is not found on server... I will not go in further explaining why, but it's the way it is and the way it should be...

    Now what I want is if sms4.txt is not on server, I want to show the included content of other txt files, and make full asp page viewable in the browser even without missed included txt file and want sms4.txt to be skipped...

    Rather than that, in reallity if there is not sms4.txt file I get error 0126 file on page view, which tells me that included file sms4.txt is not found on server...

    So how do I make page shown and other txt files included, and page to works even if any of other txt files are missed from server?


    Tnx!
     
    Error404, May 8, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    You could use the FileSystemObject to check if each file exists before including it... But i believe that the includes are done before any script is executed. So you would also have to write an include function that simply reads the file and outputs it (fairly easily done)...
     
    camjohnson95, May 11, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    If you need help doing this let me know.
     
    camjohnson95, May 11, 2009 IP
  4. emlak

    emlak Peon

    Messages:
    50
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can use fileexits method(fso)

    
    <% ' Asp -> Fso -> bay Ozgur
    
    set fso=server.createobject("scripting.filesystemobject")
    if fso.fileexists(server.mappath("file_address/file_name")) then
    %>
    <!--#include file="filename.txt"-->
    
    <%
    end if
    %>
    
    
    Code (markup):
     
    emlak, May 14, 2009 IP