Display Your Code

Say you want to write an article about web code/technology. How do you put html/asp/asp.net/php/etc. code in an ASP page and just display it (e.g., view the source)? How do you tell the server you just want to display the code and not execute it? Here is a solution:

Set fs = CreateObject("Scripting.FileSystemObject")
 Set thisfile = fs.OpenTextFile(whichfile, 1, False)
 do while not thisfile.AtEndOfStream
 response.write server.htmlencode(thisline) & "<br>"
 set thisfile=nothing
 set fs=nothing

What happens here is:
  1. Use the File System Object to read a line of the ASP page.
  2. Check if we are at the end of the page
  3. If not use server.htmlencode to write that line to the browser

display code asp Server.MapPath graphics FileSystemObject fso

Back To Top
© 1998 - 2018 psacake.com | My3C's

Version 7.2 | Advertise on this site