| This page shows the actual source code used on this site. If this is the first CYA source code you've seen you should read this overview first. Did you know you can download all the source code (and the database) of this site? Then get my newsletter to be emailed when I update the source code!
Please spread the word by recommending my site to your friends and colleagues! | This is JScript (server-side JavaScript), not the more common VBScript. More... |
utils/ShowFile.asp<%
// ============================================
// NOTE: all source code downloaded from CoverYourASP was written by
// James Shaw (unless stated otherwise), and is copyright (c) 2000-2002
// by James Shaw. You can use the code for any purpose, but do not
// publish or distribute the content in any way.
//
// See http://CoverYourASP.com/Legal.asp for up-to-date details.
// ============================================
// have we advertized our newsletter yet?
var bDoneLink = false;
var sPreSearch = '<span style="color: #000000; background-color: #66ffff; border: 0px #66ffff;">';
var sPostSearch = '</span>';
// ============================================
// display the contents of the given file
// ============================================
function ShowFile ( oFSO, sFile, bPassHTML, bShowName, bLiveLinks, sSearch )
{
var ForReading = 1;
// var ForWriting = 2;
// var ForAppending = 8;
// open asp file for reading
var fFile = oFSO.OpenTextFile ( Server.MapPath( sFile ), ForReading );
// read entire file contents into variable
var s = fFile.ReadAll ( );
// close the file ASAP to free resources
fFile.Close ( );
if ( !bPassHTML )
{
// replace & with & so HTML displayed, not interpreted
s = s.replace ( /&/g, '&' );
// replace < with < so HTML displayed, not interpreted
s = s.replace ( /</g, '<' );
// replace newline with HTML equivalent
s = s.replace ( /\n/g, '<br>' );
// replace 2 spaces with non-breaking spaces
s = s.replace ( / /g, ' ' );
// replace tabs with 3 spaces
s = s.replace ( /\t/g, ' ' );
// find hyperlinks
if ( bLiveLinks )
s = s.replace ( /(http\:\/\/([a-zA-Z0-9=\?\&\-\.\_\;\/])*)/gi, '<a href="$1" target="CYAExternal">$1</a>' );
// s = s.replace ( /(https?\:\S*)/gi, '<a href="$1" target="CYAExternal">$1</a>' );
// find search strings
if ( sSearch != undefined && sSearch.length )
{
var re = new RegExp ( sSearch, 'gi' );
s = s.replace ( re, sPreSearch + sSearch + sPostSearch );
}
// change font color for source code
s = '<font color="black">' + s + '</font>';
// show filename if wanted
if ( bShowName )
s = '<h4>' + sFile + '</h4>' + s;
}
// output the data
Out ( s );
}
// ============================================
// show a source file outside the table
// ============================================
function ShowSource ( oFSO, sFile, bShowName, bShowLink )
{
// advertize our newsletter before the first source file
if ( bShowLink && !bDoneLink )
{
bDoneLink = true;
Out ( '<p><a href="CYA.asp"><img src="images/source.gif" align="left" hspace="10" border="0"></a>Did you know you can <a href="CYA.asp">download</a> all the source code (and the database) of this site? Then <a href="subscribe.asp">get my newsletter</a> to be emailed when I update the source code!' );
Out ( '<p>Please spread the word by <a href="Recommend.asp">recommending my site</a> to your friends and colleagues!' );
Out ( '<p><table bgcolor="#dddddd"><tr><td>' );
Out ( 'This is JScript (server-side JavaScript), not the more common VBScript.</b> <a href="Snippet.asp?snip=49">More...</a>' );
Out ( '</td></tr></table>' );
}
Out ( '<p><table cellpadding="10"><tr><td bgcolor="#ff9900">' );
// show source file
ShowFile ( oFSO, sFile, false, bShowName, false );
Out ( '</td></tr></table>' );
}
%> |
Hopefully much of this is self-explanatory. If not, or if you see ways that I can improve the code, please drop me a line. To see the source code for this page, click on the icon below.  | |