473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to Read Text file in ASP

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


Jul 19 '05 #1
2 2213
<%
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 <si**********@asd.com> wrote in message
news:uv**************@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>
--------------------

Jul 19 '05 #2
thanks for your help.

"Steven Burn" <nobody@PVT_it-mate.co.uk> ¼¶¼g©ó¶l¥ó·s»D
:el**************@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 <si**********@asd.com> wrote in message
news:uv**************@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>
--------------------


Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Flynn | last post by:
hi, having problems reading from and writing back to the same file. basically, i want to read lines of text from a file and reverse them and write them back to the same file.. it has to...
1
by: Magix | last post by:
Hi, I have these string data: str_data1, str_data2, str_data3, which capture some value after a routine process A. Then I would like to write (append) these 3 string values into a text file each...
35
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
3
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its...
3
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I try to follow Steve's paper to build a database, and store a small text file into SQL Server database and retrieve it later. Only difference between my table and Steve's table is that I use NTEXT...
3
by: Ray | last post by:
Hello World, I made a Windowsform that reads data from a CSV file. It works fine, but when I have read the data of a record I have to re-Debug the form to read another record. So when I put a...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to read a file line by line (with std::string line)....
6
by: portCo | last post by:
Hello there, I am creating a vb application which is some like like a questionare. Application read a text file which contains many questions and display one question and the input is needed...
0
by: alivip | last post by:
Is python provide search in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name camry and file name corola,...
4
by: Keith G Hicks | last post by:
I'm trying to read a text file and alter the contents of specific lines in the file. I know how to use streamreader to read each line of a file. I'm doing that already to get the data into a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.