473,394 Members | 1,567 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,394 software developers and data experts.

How do I display text from simple .txt file?

Can anyone tell me how to read text from a text file (.txt) and output it on
my web page. I am currently using asp.net VB. I know all about
entering/retriving data from a database but no help documents actually detail
how to handle files.

Any help would be most appreciated.
Jul 21 '05 #1
1 1174
Hi Shodan,

To read a file you typically call File.Open and Read from the FileStream,
directly or through a StreamReader.

The easiest way is probably.

StreamReader sr = new StreamReader(filepath);
string s = sr.ReadToEnd();
sr.Close();

The text is now in s, decoded as UTF-8. Any other text encoding you need
to specify it in one of the overloaded StreamReader constructors.

With Framework 2.0 this process has been simplified with the methods

File.ReadAll(filepath)
File.ReadAllLines(filepath)
File.ReadAllBytes(filepath)

There are other people who knows more about the best ways to display the
content on a web page.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2

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

Similar topics

1
by: David Thomas | last post by:
Hi there, a while ago, I posted a question regarding reading japanese text from a text file. Well, since I solved the problem, I thought I'd post my solution for the benefit of other people with...
1
by: Agency | last post by:
I'm still working on the bpm counter. I need to have at least 2 displays that are not static. One would be a clock/running time and the other would should the current beat count. How would I...
0
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match...
1
by: Bart Van der Donck | last post by:
Jomo (jomo@dynamicdeveloper.co.uk) wrote: > How do I generate a request from an HTML search form > (or button/hyperlink) to search/query an XML data file, > using CGI scripts, and have the...
5
by: David Elliott | last post by:
I need a control on a Web Page that can accept an HTML Document and will display it. Any help would be appreciated. Thanks, Dave Here is what I was trying...
1
by: shodan | last post by:
Can anyone tell me how to read text from a text file (.txt) and output it on my web page. I am currently using asp.net VB. I know all about entering/retriving data from a database but no help...
3
by: maylee21 | last post by:
hi, anyone can help me figure out how to read data from a text file like this: 10980012907200228082002 and extract the data according to this kind of format: Record type 1 TY-RECORD ...
2
by: dmk | last post by:
Hi Again, I am reading a document into a page and then displaying it as source code (this is for an assignment.) I feel that the output that I am getting is a little hard to read, and want to...
9
by: jma | last post by:
Hi all, my application produces a log file in XML and I want my users to be able to see this log file nicely formatted through either IE or FF, but there is only client side code (no web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.