Results 1 to 7 of 7

Thread: Loading text files to html output

  1. #1
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default Loading text files to html output

    So I am learning ASP and I want to display the source code (straight text) of an asp file in the html responce. Like this
    http://www.w3schools.com/asp/showasp...=demo_fornext2
    The argument demo_fornext2 is passed to showasp.asp and the html responce displays the actual text of the demo_fornext2.asp file

    How would I code this, ie the code for the showasp.asp file? I am already reading up on it, but if anyone wants the practice



    EDIT : WARNING IE USERS . There is a terrible virus in the link below. Avoid actually clicking it and browsing there. It is given as an example, see "mywebsite" domain, but there is actually a virus somewhere there. IE users, you were warned, get firefox or something .
    Last edited by crosswire; Jun 16, 2005 at 06:30 AM.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  2. #2
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    I have already done this. On my forum, i have a link that shows the source code of the asp page the user is currently viewing.

    Here's my file called source.asp that takes the name of an asp file via the query string, and displays it via text.

    Code:
    <%
    file = Request.QueryString("page")
    IsAllowed = GetPermission(file)
    
    Response.Write "<html>" & vbNewLine & _
    		"<head><title>ASP Source for " & file & "</title></head>" & vbNewLine & _
    		"<body>" & vbNewLine
    		
    
    if IsAllowed = true then
    	Set fso = CreateObject("Scripting.FileSystemObject")
    	Set objFile = fso.OpenTextFile(server.mappath(file), 1, False)
    	thisfile = objFile.readAll
    
    	objFile.Close
    	set objFile = nothing
    	set fso = nothing
    	
    	Response.Write "<div align=""center""><a href=""javascript:window.close()"">Close Window</a></div>"
    	Response.Write "<pre>" & server.htmlencode(thisfile) & "</pre>"
    	Response.Write "<div align=""center""><a href=""javascript:window.close()"">Close Window</a></div>"
    else
    	Response.Write "You do not have permission to view the source code of this page."
    end if
    
    Response.Write "</body></html>"
    
    function GetPermission(page)
    Dim arDeniedFiles(3)
    arDeniedFiles(0) = "config.asp"
    arDeniedFiles(1) = "setup.asp"
    arDeniedFiles(2) = "source.asp"
    
    	if instr(page,"/") > 0 or instr(page,"\") > 0 then
    		GetPermission = False
    		exit function
    	end if
    	if page = "custom_login.asp" then
    		file = "\custom_login.asp"
    		GetPermission = True
    		exit function
    	end if
    	for i = 0 to ubound(arDeniedFiles)
    		if page = arDeniedFiles(i) then
    			GetPermission = False
    			exit for
    		else
    			GetPermission = True
    		end if
    	next
    end function
    %>
    The GetPermissions() function prevents users from seeing the source of critical files that I have. Otherwise, they would be able to see the source of any file. So keep that in mind.
    I gave permission to a special file called custom_login.asp.

    All that is needed to view the source of a file is go to the following example:
    http://www.mywebsite.com/source.asp?page=index.asp

    This will show the source of the index.asp file. I usually display the source in a new window, hence why I have a "Close Window" link. But you can customize this to your needs.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  3. #3
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Thank AA!

    This is perfect to learn from

    The link did not work so I just browsed. Did I need to login?

    Anyway thanks again, I got what I looked for
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  4. #4
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by crosswire
    Thank AA!

    This is perfect to learn from

    The link did not work so I just browsed. Did I need to login?

    Anyway thanks again, I got what I looked for
    Uhmm, the link was an example. It's not a real site. lol

    But you're welcome for the code.
    If you have any questions, let me know.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  5. #5
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default



    I was working with your source asp file in my web directory and it works well and has close buttons for clicking.

    I will just modify the code to get it exactly like the site of http://www.w3schools.com/asp/showasp...=demo_fornext2

    Thanks again
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  6. #6
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    Picked up a virus from the example link so I placed some warnig bouys around it. If I was to bouy the entire internet like that then it would take some centries well.

    Back to the code, Anyone can repeat this program by seting up IIS and the web directory on their machine. The proceedure is laid out at http://www.w3schools.com/asp/default.asp and it is easy to follow
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  7. #7
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Quote Originally Posted by crosswire
    Picked up a virus from the example link so I placed some warnig bouys around it. If I was to bouy the entire internet like that then it would take some centries well.
    How? You using IE? I disabled the link in my post. Sorry about that. Didn't know such a site existed.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •