Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

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

combobox

  • Please log in to reply
No replies to this topic

#1 Crock

Crock

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 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);
 line=readfile.ReadToEnd();
 textbox2.Text(line);
 readfile.close();
 readfile=Null;
}

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.

Edited by Roger, 07 July 2011 - 01:58 PM.

  • 0





Also tagged with one or more of these keywords: combobox

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