...

View Full Version : server side VBScripting



SigmaX
08-04-2004, 08:07 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>

Roy Sinclair
08-05-2004, 07:57 PM
Actually the problem may be more in where you placed the PDF file and whether the IIS user account has permissions to read the file from that location (make sure it's appropriate for IIS to have permissions there as well, you don't usually want to give root access to any drive to IIS since it makes most files on that drive accessible to IIS).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum