How to Read Text file in ASP

S

sincethe2004

Hi, I'm write an asp to include part of a text file into my asp output html,
I use FileSystemObject to get the content of the text file,
but the asp just hang when it runs,
the source code is listed below if anyone could help:
--------------------
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<%
if (String(Request.QueryString("page")) == "undefined" ||
String(Request.QueryString("page")) == "")
{
Response.Write("Please specify the page data.");
Response.End()
}

var sFile = Server.MapPath(String(Request.QueryString("page")));
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (!fso.FileExists(sFile)) {
Response.Write("No Such File : " + String(Request.QueryString("page")));
//Response.Redirect(".");
Response.End();
}

var f = fso_OpenTextFile(sFile, 1); //1 -- ForReading
var sFileTxt = f.ReadAll();
f.Close();

%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<%= sFileTxt %>
</body>
</html>
--------------------
 
S

Steven Burn

<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FileObject, SomeFile, InputStream, PrintLine, LineCount
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
SomeFile = Server.MapPath("myfile.ext")
Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
LineCount = 0
Do While Not InputStream.AtEndOfStream
LineCount = LineCount + 1
PrintLine = InputStream.ReadLine() + "<br>" + PrintLine
'do something with the contents......
Loop
InputStream.Close
Set OutputStream = Nothing
Set FileObject = Nothing
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 
S

sincethe2004

thanks for your help.

Steven Burn said:
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FileObject, SomeFile, InputStream, PrintLine, LineCount
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
SomeFile = Server.MapPath("myfile.ext")
Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
LineCount = 0
Do While Not InputStream.AtEndOfStream
LineCount = LineCount + 1
PrintLine = InputStream.ReadLine() + "<br>" + PrintLine
'do something with the contents......
Loop
InputStream.Close
Set OutputStream = Nothing
Set FileObject = Nothing
%>

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top