![]() |
|
|
|
||||||||||
![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
Include some file, if not found than include other?
Hi, I'm very new to ASP...
So I have this code on my page Code:
<!--#include file="somefile.txt"--> Now what I want is that if somefile.txt is not found on server, I wan't the content of another textual file to be shown (someotherfile.txt) so I need something like Code:
<!--#include file="somefile.txt"--> if file not found then <!--#include file="someotherfile.txt"--> Thanks... |
|
#2
|
|||
|
|||
|
I assume it's ASP Classic (VBScript) .. if so then do as follows:
Code:
Dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile "c:\somefile.txt", True
If filesys.FileExists("c:\somefile.txt") Then
<!--#include file="somefile.txt"-->
Else
<!--#include file="someotherfile.txt"-->
End If
|
|
#3
|
|||
|
|||
|
Btw, if it's an ASP.NET project then you can use the following code:
Code:
If IO.File.Exists(Server.MapPath("somefile.txt")) Then
' do something
Else
' do something else
End If
|
|
#4
|
||||
|
||||
|
Quote:
However, THIS will work: Code:
Dim filesys
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CreateTextFile "c:\somefile.asp", True
IF filesys.FileExists("c:\somefile.asp") THEN
Server.Execute("somefile.asp")
ELSE
Server.Execute("someotherfile.asp")
END IF
Let me know if this helps you out! |
|
#5
|
|||
|
|||
|
I agree Include function as is will not work ... however you can use the fylesys object to read the somefile.txt content and show up its content ...
Code:
Dim content
Set content = filesys.OpenTextFile("c:\somefile.asp")
Response.Write(f.ReadAll)
content.Close
|
|
#6
|
|||
|
|||
|
Quote:
|
|
#7
|
||||
|
||||
|
Correct, it will output the file, but will not execute any ASP code inside.
|
|
#8
|
|||
|
|||
|
You have to read text file and execute it with execute(str) in ASP
This is the only way to dynamic include a file in ASP |
|
#9
|
|||
|
|||
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Include file with variable, like file.php?var=1? | 123GoToAndPlay | PHP | 4 | Apr 16th 2008 12:29 pm |
| How to add php include & cgi include statments to html file | spencermjax | HTML & Website Design | 0 | Apr 16th 2008 6:50 am |
| How to include a out file? | yaman | PHP | 6 | Mar 30th 2008 12:17 am |
| Include a php Template file in a HTML file | goldendragon | PHP | 7 | Aug 31st 2007 10:31 am |
| include('$file'); | promotingspace.net | PHP | 12 | Jun 28th 2007 11:38 am |