SIGN UP MEMBER LOGIN:    
Resource

How to read a text file in C#?

Soft Dev Resources Jul 04, 2009
How to read a text file in C#?
This code snippet shows how to read a text file in C#. You must change the path in StreamReader below to your correct file. 

Simply create a console application and copy and paste this code below.

using
System;
using System.IO;

class ReadTextFileSample
{
public static void Main()
{
try
{
using (StreamReader sr = new StreamReader(@"C:\MyTextFile.txt"))
{
String line;

while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);

}
}
}
share this resource :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Sponsored by
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor