Solved

VBScript&ASP: want to check the existence of a file on the server !

Posted on 1998-09-04
2
154 Views
Last Modified: 2010-04-30
Hi.

I have a NT server with IIS4 etc.
I build a web site that use ONLY html, vbscript, asp.
The website is called "Website"
The directory is: "c:\InetPub\wwwroot\Website"

The actual page is "page.asp"

I want to display in the returned file ("page.asp") when the client("slave") asks for "page.asp" to the server ("master") a link only if a specified file is present on the server in "c:\InetPub\wwwroot\Website"
This page is called "present.asp"

If this page exits by a click on this link you'll jump to it
If this page doesn't exist you'll jump to "ouch.asp"

Please ask for more infos if i'm not understandable.

Thanx

A+rno
0
Comment
Question by:arnaudg
2 Comments
 
LVL 1

Accepted Solution

by:
soeding earned 50 total points
ID: 1433052
arnaudg,
put this into "page.asp":

<%
On Error Resume Next

' See if present.asp has any content:
Set fs = CreateObject("Scripting.FileSystemObject")
Set ts = fs.OpenTextFile(Server.MapPath("/PathFromTheRoot") + "\present.asp")
txt = ""
txt = ts.ReadLine
ts.Close

' Create Link:
If txt = "" Then
  Response.Write "<a href='ouch.asp'>myLink</a>"
Else
  Response.Write "<a href='present.asp'>myLink</a>"
End If
%>

Regards
0
 
LVL 1

Author Comment

by:arnaudg
ID: 1433053
Thanx for your good answer.

Just one question more.
I tried to put your script as a function.
Function testfile()
.
End Function

And put a onclick="testfile()" in a <A></A> tag.
It doesn't work.

Could you tell me why ?

Thanx again.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Check Disk (CHKDSK) on all volumes and fix if needed. 8 178
Using "ScreenUpdating" 6 55
How to compare ms sql hashbytes results within vb6 5 55
Spell Check in VB6 13 96
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now