print from txt file

O

Oli

Hi,

Ok, last question of the day!

Can I have the contents of a *.txt file simply being printed on a page
(presumably by using response.write)?

Many thanks for all your help today,
Oli
 
R

Ray at

Not ~printed~ since that would be something the user would have to do, but
if you mean displayed in the page, you can <!-- #include
file="yourfile.txt" --> it or Server.Execute "file.txt" it.

Those are two options.

Ray at work
 
A

Aaron Bertrand - MVP

Also, you could use Scripting.FileSystemObject to open the file and read it
(e.g. if you wanted to parse the contents, or only show certain lines, etc.)

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
 
A

Aaron Bertrand - MVP

While not myTextFile.AtEndOfStream
Response.Write(myTextFile.ReadLine & "<br>")

Ugh... a loop? Why? How about:

Response.Write Replace(myTextFile.ReadAll(), vbCrLf, "<br>")

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




Wend
myTextFile.Close


Regards,
Bhaskardeep Khaund
 
R

Ray at

Why go line by line? Just readall and replace vbCrLfs with <br>s or use the
<pre> tag.

Ray at work


"Bhaskardeep Khaund" in an HTML message:

You can do this...

Set myObject = Server.CreateObject("Scripting.FileSystemObject")
Set myTextFile = myObject.OpenTextFile(Server.MapPath("../../textfile.txt"))
While not myTextFile.AtEndOfStream
Response.Write(myTextFile.ReadLine & "<br>")
Wend
myTextFile.Close


Regards,
Bhaskardeep Khaund
 
B

Bhaskardeep Khaund

Hi,

You can do this...

Set myObject = Server.CreateObject("Scripting.FileSystemObject")
Set myTextFile = myObject.OpenTextFile(Server.MapPath("../../textfile.txt"))
While not myTextFile.AtEndOfStream
Response.Write(myTextFile.ReadLine & "<br>")
Wend
myTextFile.Close


Regards,
Bhaskardeep Khaund
 
B

Bhaskardeep Khaund

Hi,

I have used the loot because, if the content of the text file is too big it would be an extra strain on the server. And when using the loops u could format each sentence, leading to more flexibility. I think its a matter of coding style. Whats say?

Bhaskardeep Khaund
 
A

Aaron Bertrand [MVP]

Please post in plain text. These HTML attachments are annoying, and so is
having to switch from HTML mode when replying. I think we just found #5007!
 

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

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top