Jump to content

Check out our Community Blogs


Member Since 05 Jul 2011
Offline Last Active Jul 31 2011 05:16 AM

Topics I've Started

[C#] how to read data from a text file

05 July 2011 - 02:35 AM

This is my first tutorial snippet and i will be telling how to view data from text file.
I will be using Microsoft Visual Studio 2005.

The code is as following:

First we will use the namespace "System.IO" as we will be viewing output from the text file.

using System.IO;

then the code will be in braces like this.

 String line=Null;
 System.IO.Textreader readfile=New Streamreader("C:\\" + textbox1.Text);

There may be some errors in this code as i am new to this particularly if readfile.close() gives error then remove the brackets.The name of the file you write in the text box1 must already exist the entire data of the file will be displayed in text box2.to create a file.

 create.file("C:\\" + textbox1.Text);

You can also use combobox to display data of textfile.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download