"hoke" wrote:
: I want to display plain text files in the browser. The files contain html
and javascript and have a .txt extension.
:
: This works fine with files with just html. Unfortunately when showing
files with javascript, I get an "error on page" warning and the page is not
displayed. I suppose that when Internet Explorer discovers a <script> tag he
starts to interpret it. This is not what I want. After all Internet Explorer
is a browser and not an interpreter.
:
: Can anybody tell me, or refer me to some documentation, about the reason
why Internet Explorer is not just displaying plain text files as they are.
:
: How can I send plain text files to the client and tell the browser: do not
interpret this page, just display it. I suppose it has got something to do
with MIME types but i am not sure.
:
: A workaround would be welcome aswell.
:
: I discovered that everything between <textarea></textarea> tags is
displayed as it is (even other tags) but I prefer to display the file
itself.
Hoke...
You do not need to save an additional version of your server-side code with
..txt.
Just use this to view the original source. Change the file name from
somefile.asp to your file and include a path to get there if it is not in
the same directory. I usually save this file with a prefix to the original
source file name, i.e. ss_somefile.asp.
DO NOT modify this file to pass arguments to it because that will allow
anyone to view any file you have.
<%@ Language=VBScript %>
<%
Dim strURL
strURL = "somefile.asp"
Dim strDir, strFileName
strDir = Request.ServerVariables("APPL_PHYSICAL_PATH")
strFileName = Replace(strURL,"/","\")
strFileName = strDir & strFileName
Const ForReading = 1
Dim objFSO, objTextStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(strFileName, ForReading)
Response.Write "<HTML><BODY>"
Response.Write "<XMP>" & objTextStream.ReadAll & ""
Response.Write ""
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing
%>
HTH...
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp