Click to See Complete Forum and Search --> : Server-side VBScripting


SigmaX
08-04-2004, 01:53 PM
Hi, I have recently started learning VBScript and ASP. I have written a little script that opens a .pdf file (which is ON the SERVER) after checking (obviously on the server-side) and making sure that it exists and can be opened and finally displays it in the browser. The script works find when testing it from a browser on the server computer. But when I try viewing the .asp page from other computers (using IE or Mozilla) they try to open the file using an editor (ie. Dreamweaver). I've tried forcing it to open it directly but they keep launching an editor to open the page. I think my problem is that the script is being run locally rather than on the server when I'm on other computers. This I'm guessing has to do with the 'runat=server' setting. Could you please look at my code and tell me how to fix this. Thank you all. Here's the script: I think I have the runat=server tags wrong.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@ Language=VBScript %>

<html>
<head>
<title>Open PDF Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
color: #990000;
font-size: 14px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<span class="style1">Please be Patient While Opening Requested File. Thank you.<BR></span>

<script language="VBScript" runat="server">

Response.Write "Checking File... <BR>"

Const Filename = "/test.pdf" ' file to read
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

' Create a filesystem object
Dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")

' Map the logical path to the physical system path
Dim Filepath
Filepath = Server.MapPath(Filename)

if FSO.FileExists(Filepath) Then
'At this point we know that the document exists.
' Get a handle to the file
Response.Write "<p><b>File Exists...</b></p><hr>"
Response.Write "<p><b>Checking Availability...</b></p><hr>"

Dim fil, retcode

'Catch Errors from this point on...
On Error Resume Next

set fil = FSO.GetFile(Filepath)

' Open the file
Dim TextStream
Set TextStream = fil.OpenAsTextStream(ForReading, TristateUseDefault)


if Err.Number <> 0 then
'At this point we know that the existing document cannot be opened.
Response.Write "<p><b>File Not Available. Maximum Number of Users Reached...</b></p><hr>"
'fileNotAvailable()
retcode = "error"
Err.Clear
else
'If document can be opened, then, launch document in browser.
TextStream.Close
Response.Write "<p><b>File Ready For Viewing...</b></p><hr>"
</script>
<INPUT TYPE='button' VALUE='Open File' onClick='location="test.pdf"'>

<script language="VBScript" runat="server">
'openPDF()
end if

Set TextStream = nothing
Else

Response.Write "<p><b>File: " & Filename & " </b></p><hr>"
Response.Write "<p><b>File Does Not Exist...</b></p><hr>"
'fileNotFound()
</script>
<form>
<input type="button" value="Close Window (For IE Users)" onClick="self.close()">
</form>


<script language="VBScript" runat="server">
End If

Set FSO = nothing
</script>
</body>
</html>

buntine
08-04-2004, 08:25 PM
Ok, what you have done here is constructed your code to run from the client. You need to use the script delimiters provided by ASP.

code in HTML
<%
code in ASP
%>
back in HTML

You should definetely read the following ASP tutorial: http://www.w3schools.com/asp/default.asp
Also, www.asp101.com should be helpful.

Regards,
Andrew Buntine.

Bruce Lim
09-26-2004, 10:36 PM
Hi all,

Does anyone know how to make a page expires even when the back button on the browser is clicked?

For example

I got this Page A.
When i submit the result posted from Page A ,
It will post a result to Page B

When i click on the back button, it will redirect them to another page to show them " an invalid page"

how do i code?


Thank alot

buntine
09-26-2004, 11:56 PM
Its not a coding issue. Its the way server-side programming works. The back button cant be used because the data that the page requires has expired. To go back to the referring page, you need to generate a link, which will serve the page again.

Regards.

Bruce Lim
09-27-2004, 12:54 AM
hi butine,

I just want the previous page to be expire.
Just like some website, when you fill in the form and click the post button, it will submit the result and show "Result updated". When you purposely click on the "BACK" button of your browser, it will tell you that a page has expired.

how do you do that?

chrismartz
09-28-2004, 08:23 PM
you could have the form set a cookie and then request that cookie and if the cookie isn't there than have them be able to fill out the form but if it is, put <%= response.write "Page Expired" %> this what you meant?