CodeAve.com CodeAve.com - ASP - Read/Write
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


Link & Display Text Files
Linking and displaying text files within a single document is a snap in asp.  All of the text files contain the title as the first line.  The first line will be read and hyperlinked in the default view.  When clicked the file name is passed to the same page as a querystring variable.  Providing that the text document exists (this is to prevent errors from user typing in the address bar) the full contents of the document will be displayed.  This is an excellent way to make copybooks and file layouts available online.
View the Output
Text View
Print View
Mail this Link
Download the Code

<html>
<body bgcolor=#FFFFFF>
<title>CodeAve.com(Link & Display Text Files)</title>

<%

u_file=trim(request.querystring("u_file"))
if u_file = "" then

' Get the top level directory info
dir_info = request.servervariables("appl_physical_path")

' Get the rest of the directory info without the first / 
dir_info = dir_info + right(request.servervariables("script_name"),(len(request.servervariables("script_name"))-1)) 

' Split the directory info by /
g_input=split(dir_info,"/")

' Count the number of splits
num_inputted=ubound(g_input)-1

set directory=server.createobject("scripting.filesystemobject")
set allfiles=directory.getfolder(server.mappath("../"&g_input(num_inputted)))

' Lists all the files found in the directory
For each directoryfile in allFiles.files 

' Removes ASP pages from view 
if (right(directoryfile.name,3)) <> "asp" then 

set fso = createobject("scripting.filesystemobject")
set act = fso.opentextfile(server.mappath(directoryfile.name))

read_text = act.readline
act.close

%>

<a href=<%
' Write out the name of the page
response.write request.servervariables("script_name") %>
?u_file=<%
' Write out the name of the document
response.write server.urlencode(directoryfile.name) %>
><%
' Write out the first line of the document
response.write server.htmlencode(read_text) %>
</a><br>
<% 
'End check for any pge other than ASP
end if 

' End for next loop to list documents
next 
' End check for querstring input
else

set fso = createobject("scripting.filesystemobject")

' Check to see if the file in the querystring exists
' (This prevents user input in the address bar from causing errors)
if fso.FileExists (server.mappath(u_file)) then 
' Open the file and read it
set act = fso.opentextfile(server.mappath(u_file))
read_text = act.readall
act.close

' Write the contents of the document ot the browser
Response.Write "<pre>" & server.htmlencode(read_text) & "</pre>"

' If the file in the querystring does not exist
' Display and eror message
else 
%>

There was a problem displaying the requested item<br>
Please go <a href=<%= request.servervariables("script_name")%>>back</a> and select again<%

' End check for file existence
end if 

' End check for querystring value
end if
%>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3