|
SerenityNet -> RE: Showing a txt file in IE (2/27/2002 13:26:12)
|
Perfectly Simple ! ! ! Totally Useful Code ! ! ! "Thank you" William, Katherine, Spooky, and everyone that contributes to the OutFront forums. This has to be the best web help community ever! I can see how the code William has written here could be very useful to someone that wants to populate web pages, or page elements, with txt file information sent or uploaded by a client. For this reason, I'm summarizing this thread's discussion in the text below. -------------------------------- Goal: Have a web page, or element within a web page, display a separate txt file document while constraining the width of the display as desired (so the viewer doesn't have to scroll the viewing window left and right). 1. You will need a web page (let's call it "Page1") where you place hyperlinks to a separage page (let's call it "display.asp") that will display the txt file (called "FileOne.txt"). The hyperlink on Page1 is: <a href="display.asp?TxtFileName=FileOne.txt">DisplayFileOne</a> For another file, use another hyperlink, like: <a href="display.asp?TxtFileName=FileTwo.txt">DisplayFileTwo</a> 2. Create a new page and call it "display.asp". The following code is placed between the <body> tags in the "display.asp" page where you want the txt file to appear. (This one code will work for all hyperlinks directed to it.) <% sFile=Request("TxtFileName") Set FSO = CreateObject("Scripting.FileSystemObject") Set objM = FSO.OpenTextFile(Server.MapPath(sFile)) MsTxt = objM.ReadAll objM.Close MsTxt=Server.HTMLEncode(MsTxt) MsTxt=Replace(MsTxt,vbCrLf,"<BR>") MsTxt= "<Left><Table Width='600'>" & MsTxt MsTxt= MsTxt & "</Table></Left>" Response.Write MsTxt %> 3. Of course, there are variations you can use. Other Notes:- If your txt file is in a different directory than the display.asp page then your hyperlink on Page1 needs to identify the path to the txt file, like:
<a href="display.asp?TxtFileName=Directory2/FileOne.txt">DisplayOne</a> - The line "MsTxt=Server.HTMLEncode(MsTxt)" can be deleted if you would like html tags within the txt file to work. If left off then javasript and asp code within the txt file will also be implemented.
- You can change the width value to whatever you want.
- This even displays correctly in Netscape 4.75+ Wow!
- Don't forget to look at Katherine's use of the <pre> tag in the thread above. If you choose to have the txt file containing HTML code then you may find the <pre> tag very useful.
4. Code Snippets- If you want a copy of the snippets I've collected (why this thread started) then right-mouse-click on the hyperlink below & "Save target as..."
http://www.serenitynet.net/downloads/snippets.txt - If you want, send me snippets you've found really useful. As I have time, I'll add them to the file at the url above. Just e-mail them to me in a txt file ready to copy and paste into the existing file. Try to give credit to your source.
Andrew webmaster@serenitynet.net - But the fruit of the Spirit is love, joy, peace, patience, kindness, goodness, faithfulness, gentleness, and self-control..." Gal. 5:22
|
|
|
|