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>
--------------------

Re: How to Read Text file in ASP by Steven

Steven
Thu Feb 05 07:11:27 CST 2004

<%
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)


sincethe2004 <sincethe2003@asd.com> wrote in message
news:uv2AMZ96DHA.1716@TK2MSFTNGP10.phx.gbl...
> 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>
> --------------------
>
>
>
>



Re: How to Read Text file in ASP by sincethe2004

sincethe2004
Fri Feb 06 09:03:02 CST 2004

thanks for your help.

"Steven Burn" <nobody@PVT_it-mate.co.uk> ¼¶¼g©ó¶l¥ó·s»D
:elatYn#6DHA.2064@TK2MSFTNGP11.phx.gbl...
> <%
> 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)
>
>
> sincethe2004 <sincethe2003@asd.com> wrote in message
> news:uv2AMZ96DHA.1716@TK2MSFTNGP10.phx.gbl...
> > 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>
> > --------------------
> >
> >
> >
> >
>
>