Simple ASP Application

Tuesday Oct 27th 1998 by ServerWatch Staff
Share:

This application was my first endeavor into the world of ASP. It evolved from a VB program I had written to handle directory browsing  for a site running Sambar 4-1. The application itself was designed to handle a problem sharing reports coming off a mainframe...

by Bob Dombroski

This application was my first endeavor into the world of ASP. It evolved from a VB program I had written to handle directory browsing  for a site running Sambar 4-1. The application itself was designed to handle a problem sharing reports coming off a mainframe. The only solution prior to this application was to wait a few hours(or days) to get the report to paper and hand deliver it(even if you only needed 10 pages out of 100 page report).

The application design: this application assumes the report files have a .txt extension

  1. Get the report from the mainframe to the web site(in a text format). This is easy using FTP. If you need more info on this aspect email me and I will try to help you set up the FTP server.
  2. Allow browsing of the received report files.
  3. View the report files. Here we will allow options to view an enhanced report, or a standard report. The enhanced report does stuff like turns negative numbers to red and adds a green-bar or grey-bar background. The standard report is jst a link to the text file.

 

THE CODE.


' We use the server object called mappath which gives the physical path to a virtual directory(or file). This assumes you have a virtual directory called REPORTS.

FTP_VIRTUAL_PATH = "/REPORTS"

FTP_PATH = SERVER.MAPPATH(FTP_VIRTUAL_PATH)

 

Note: The example here at Swynk.com has some added code since I dont have a reports virtual directory. The report files are in the same directory as this file.  I had to map a path from the original page and chop off the file name to get a physical path to this directory.


SET O_FSO = CREATEOBJECT("SCRIPTING.FILESYSTEMOBJECT")

SET O_FOLDER = O_FSO.GETFOLDER(FTP_PATH)

SET O_FILES_IN_FOLDER = O_FOLDER.FILES

' These three lines of code obtain a collection of files within the   FTP_PATH(folder).

 


NOTE: In the ftp job I created for the transfers, I preceed the file name with a 3 position userid to easily see who uploaded each file.  This makes finding a specific report easier. The guts of this page shows a table with 4 columns. The first shows the persons id who uploaded the file, the second  provides a link to the enhanced report(an ASP page), the third has a direct link to the report itself and the last column shows file information(creation date and size). The end result we want should look   something like this:

    Uploaded By

    Enhanced Report

  Report

  File info

KIM      4th Quarter Summary    4th Quarter Summary 09/04/98 Size : 1,328
GAR      Q4 Dept Report     Q4 Dept Report 09/17/98 Size : 5,245

The Code behind it:

First set up the table with headings:

<TABLE  BORDER = "1" WIDTH = "100%">

<TR>

   <TD WIDTH="25%"><P ALIGN = "CENTER">UPLOADED BY</TD>

   <TD WIDTH="25%"><P ALIGN = "CENTER">ENHANCED REPORT</TD>

   <TD WIDTH="25%"><P ALIGN = "CENTER">REPORT</TD>

   <TD WIDTH="25%"><P ALIGN = "CENTER">FILE INFO</TD>

<TR>

Now for the Script:

<% FOR EACH OBJFILEITEM IN O_FILES_IN_FOLDER

       USER = MID (OBJFILEITEM.NAME, 1, 3)   ' Get the user id(the first 3 chars in the file name)

       FILE_NAME = MID (OBJFILEITEM.NAME, 4, (LEN(OBJFILEITEM.NAME) - 1)) %> 'Get the file name minus the user id

      <TR>

             <TD WIDTH = "25%"><P ALIGN = "CENTER"><%=USER%></TD>                                                                                                                      'Note the<% =USER%> is a short cut it could also be coded as     <% RESPONSE.WRITE( USER ) %>  

 

<TD WIDTH = "25%"><P ALIGN = "CENTER"><A HREF = "ENHANCED.ASP?E_FILE = " <%=OBJFILEITEM.NAME%>"><%=FILE_NAME%></A><TD>

Here we create a link to the Enhanced.asp page passing it the variable E_FILE with the file name the user is requesting

<TD WIDTH = "25%"><P ALIGN = "CENTER"><A HREF = "

<% VIRTUAL_FILE = FTP_VIRTUAL_PATH + "/" + OBJFILEITEM.NAME

RESPONSE.WRITE VIRTUAL_FILE %> "> <%= FILE_NAME %> </A><TD>   This creates a link directly to the report file.

<TD WIDTH = "25%"><P ALIGN = "CENTER"><%RESPONSE.WRITE OBJFILEITEM.DATECREATED & " SIZE " & OBJFILEITEM.SIZE%></TD> Display the date the file was created and the size of the file

<TR>

<% NEXT %>

 

One of the things I am always trying to find time for is to create an administrative page which would allow for directory clean up of the reports directory. When I find the time to write it, I will post the code. If anyone has any improvements to suggest please email me and I will post your suggestions with full credit to you.

Here's the code for Enhanced.ASP

The function neg_to_red takes a string and returns a string with <font color = "red"> around all the negative numbers. This function assumes the maximum length of a line on the report is 132 and negative sign is trailing on negative numbers ex 12.23- Feel free to use the function if you ever find a need for it.

<%

function neg_to_red(line)

pos = 2

last_end = 0

Do While pos < 133

chr1 = Mid(Line, pos, 1)

chr2 = Mid(Line, (pos - 1), 1)

chr3 = Mid(Line, (pos + 1), 1)

If ((chr1 = "-") And (chr3 = " ") And (IsNumeric(chr2))) then

        pnt = pos - 1

       finished = 0

       Do While finished = 0

              If ptr < last_end Then

                 finished = 1

             Else

            If Mid(Line, pnt, 1) = " " Then

                  hold_line = "<font color = " & Chr(34) & "red" & Chr(34) & ">"

                 build_line = build_line & Mid(Line, last_end + 1, (pnt - last_end))

                 build_line = build_line & hold_line

                 build_line = build_line & Mid(Line, pnt + 1, (pos - (pnt)))

                 build_line = build_line & "</font>"

                 last_end = pos

                 finished = 1

            Else

                    pnt = pnt - 1

                   If pnt = 1 Then

                        hold_line = "<font color = " & Chr(34) & "red" & ">"

                        build_line = build_line & Mid(Line, last_end + 1, (pnt - last_end + 1))

                        build_line = build_line & hold_line

                        build_line = build_line & Mid(Line, pnt + 1, (pos - (pnt)))

                         build_line = build_line & "</font>"

                        last_end = pos

                        finished = 1

                    End If

              End If

           End If

         Loop

         End If

    pos = pos + 1

Loop

build_line = build_line & Mid(Line, (last_end + 1), pos - (last_end + 1))

neg_to_red = build_line

end function

%>

Here is the code that reads and displays the text file

<%

RESPONSE.WRITE "<BODY BACKGROUND = " & CHR(34) & "GREENBAR.BMP" & CHR(34) & ">"

'CHR(34) is a double quote the line ends up being   written as <BODY BACKGROUND = "GREENBAR.BMP">

FTP_VIRTUAL_PATH = "/REPORTS"

FTP_PATH = SERVER.MAPPATH(FTP_VIRTUAL_PATH) ' Get the physical path to the reports directory

SET O_FSO = CREATEOBJECT("SCRIPTING.FILESYSTEMOBJECT")

IN_FILE = REQUEST ("E_FILE")         'Get the file name posted to the page

FILE_NAME = FTP_PATH & IN_FILE

SET INSTREAM = FILEOBJECT.OPENTEXTFILE ( FILE_NAME, 1, FALSE, FALSE)  'Open the text file for input

RESPONSE.WRITE "<PRE>"               'Use the HTML tag <Pre>meaning the following code is preformatted(keeps the spacing)

WHILE NOT INSTREAM.ATENDOFSTREAM     'Proccess until end of file reached

   IN_LINE = INSTREAM.READLINE

   IF INSTR (IN_LINE, "-") THEN             ' If there is a negative sign in the line call the function neg_to_red

         RESPONSE.WRITE     NEG_TO_RED(IN_LINE) & "<BR>"  

   ELSE                                                          ' Else we just write back the line

         RESPONSE.WRITE      IN_LINE & "<BR>"

  END IF

WEND

%>

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved