Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 CoverYourASP --> utils/ShowFile.asp" --> Source

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
45 active users
1297 visitors today
1940 pages today
how is this done?
Tools I use

CoverYourASP
Copyright © 1999-2010 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

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 &amp; so HTML displayed, not interpreted
      s = s.replace ( /&/g, '&amp;' );

      // replace < with &lt; so HTML displayed, not interpreted
      s = s.replace ( /</g, '&lt;' );

      // replace newline with HTML equivalent
      s = s.replace ( /\n/g, '<br>' );

      // replace 2 spaces with non-breaking spaces
      s = s.replace ( /  /g, '&nbsp;&nbsp;' );

      // replace tabs with 3 spaces
      s = s.replace ( /\t/g, '&nbsp;&nbsp;&nbsp;' );

      // 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.

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems



New Proposal Kit Professional 5.1
Brand yourself as a top professional: create quotes and amazing proposals and get many legal documents free!

The latter saved me 3 times the purchase price on the first day I owned it!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...

CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?