473,803 Members | 3,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 FileSystemObjec t 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="JA VASCRIPT" CODEPAGE="1252" %>
<%
if (String(Request .QueryString("p age")) == "undefined" ||
String(Request. QueryString("pa ge")) == "")
{
Response.Write( "Please specify the page data.");
Response.End()
}

var sFile = Server.MapPath( String(Request. QueryString("pa ge")));
var fso = new ActiveXObject(" Scripting.FileS ystemObject");
if (!fso.FileExist s(sFile)) {
Response.Write( "No Such File : " + String(Request. QueryString("pa ge")));
//Response.Redire ct(".");
Response.End();
}

var f = fso.OpenTextFil e(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 2274
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim FileObject, SomeFile, InputStream, PrintLine, LineCount
Set FileObject = Server.CreateOb ject("Scripting .FileSystemObje ct")
SomeFile = Server.MapPath( "myfile.ext ")
Set InputStream = FileObject.Open TextFile(SomeFi le, ForReading, False)
LineCount = 0
Do While Not InputStream.AtE ndOfStream
LineCount = LineCount + 1
PrintLine = InputStream.Rea dLine() + "<br>" + PrintLine
'do something with the contents......
Loop
InputStream.Clo se
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**********@a sd.com> wrote in message
news:uv******** ******@TK2MSFTN GP10.phx.gbl...
Hi, I'm write an asp to include part of a text file into my asp output html, I use FileSystemObjec t 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="JA VASCRIPT" CODEPAGE="1252" %>
<%
if (String(Request .QueryString("p age")) == "undefined" ||
String(Request. QueryString("pa ge")) == "")
{
Response.Write( "Please specify the page data.");
Response.End()
}

var sFile = Server.MapPath( String(Request. QueryString("pa ge")));
var fso = new ActiveXObject(" Scripting.FileS ystemObject");
if (!fso.FileExist s(sFile)) {
Response.Write( "No Such File : " + String(Request. QueryString("pa ge")));
//Response.Redire ct(".");
Response.End();
}

var f = fso.OpenTextFil e(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_i t-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.CreateOb ject("Scripting .FileSystemObje ct")
SomeFile = Server.MapPath( "myfile.ext ")
Set InputStream = FileObject.Open TextFile(SomeFi le, ForReading, False)
LineCount = 0
Do While Not InputStream.AtE ndOfStream
LineCount = LineCount + 1
PrintLine = InputStream.Rea dLine() + "<br>" + PrintLine
'do something with the contents......
Loop
InputStream.Clo se
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**********@a sd.com> wrote in message
news:uv******** ******@TK2MSFTN GP10.phx.gbl...
Hi, I'm write an asp to include part of a text file into my asp output

html,
I use FileSystemObjec t 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="JA VASCRIPT" CODEPAGE="1252" %>
<%
if (String(Request .QueryString("p age")) == "undefined" ||
String(Request. QueryString("pa ge")) == "")
{
Response.Write( "Please specify the page data.");
Response.End()
}

var sFile = Server.MapPath( String(Request. QueryString("pa ge")));
var fso = new ActiveXObject(" Scripting.FileS ystemObject");
if (!fso.FileExist s(sFile)) {
Response.Write( "No Such File : " + String(Request. QueryString("pa ge"))); //Response.Redire ct(".");
Response.End();
}

var f = fso.OpenTextFil e(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
2672
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 replace the text its reversing eg.
1
4312
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 time after routine process A, the text file is named "mytext.dat" in following format with "#####" as separator. The maximum entries of them is 5. When reaching the fifth entry, it will delete the very first entry.
35
11506
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", "r+"); fseek(file, -2, SEEK_END); fscanf(file, "%d", &c); this works fine if the integer is only a single character. When I get into larger numbers though (e.g. 502) it only reads in the 2. Is there
3
18966
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 original form. The problem is tha the binary source that I extract from the text file seems to be diferent from the source I saved. Here is my code: 1) handle=file('image.gif','rb')
3
2963
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 datatype for the file instead of using IMAGE datatype. I can not use SqlDataReader to read the data. I need your help, Thanks. -David (1) I have a table TestFile for testing: ID int FileName navrchar(255)
3
1820
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 new seek item in the textbox after I searched for an item and click the seek button.. it seems it is doing nothing. And also... what code can I use to genereate a messagebox message when a seek item is not at all in the CSV file?
6
32923
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). Is there some way to burst read the whole file and later "extract" each line? Thanks in advance, Thomas Kowalski
6
2491
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 from user to calculate the score. Here is a problem. I can read a text file. However, it's read whole file at a time. So,
0
3878
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, file name honda contain folder accord and BMW contain file name X5 Is there way to enter name of parent folder(cars) and search in all sub folder(Toyota,Honda and BMW) and files ? how can I intgreat cod to be user interface (buttun ,text box...
4
3420
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 database. What I need help with is on how to locate a specific line in the file, change it and then save the updated text file. Can anyone help me out or point me to a site that explains this clearly? Here's part of my code that reads the contents of...
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10546
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7603
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5627
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.