Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    2
    Thanks
    0
    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"
    "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>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    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
    •