Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Thanked 0 Times in 0 Posts

    server side VBScripting

    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"

    <%@ Language=VBScript %>

    <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;
    <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>"
    retcode = "error"
    'If document can be opened, then, launch document in browser.
    Response.Write "<p><b>File Ready For Viewing...</b></p><hr>"
    <INPUT TYPE='button' VALUE='Open File' onClick='location="test.pdf"'>

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

    Set TextStream = nothing

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

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

    Set FSO = nothing

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts
    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).
    Check out the Forum Search. It's the short path to getting great results from this forum.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts