CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  How to use C# Textreader Class

Textreader and TextWriter are the another way to read and write file respectively, even though these are not stream classes. Textreader represents a reader that can read a sequential series of characters. The StreamReader and StreamWriter classes are derived from TextReader and TextWriter classes respectively, which read characters from streams and strings.

The following C# source code shows how to read a file using TextReader.

         C# Source Code Download           Print Source Code
         How to use C# Textreader Class - Download
        
C# Tutorial

using System;
using System.Windows.Forms;
using System.IO;
using System.Text;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string line = null;
                System.IO.TextReader readFile = new StreamReader("C:\\csharp.net-informations.txt");
                while (true)
                {
                    line = readFile.ReadLine();
                    if (line != null)
                    {
                        MessageBox.Show (line);
                    }
                }
                readFile.Close();
                readFile = null;
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}



CSharp File (I/O) Operations Related Contents
*     How to use C# Directory Class
*     How to use C# File Class
*     How to use C# FileStream Class
*     A simple C# Text Reader source code
*     How to use C# TextWriter Class
*     How to use C# BinaryWriter Class
*     How to use C# BinaryReader Class


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.