C# program to read text from a file

In this C# program, we are going to learn how to read text from a file? Here, we are using Method ReadAllText() of “File” class to read text from a file.
Submitted by IncludeHelp, on October 28, 2017

Given text, and we have to read text from the file using C# program.


This is a static method of "File" class, which is used to read all text from a file.


string File.ReadAllText(path);


  1. path - Filename with its location.

Return Value:

  1. string - Returned string that contains text which is written into text file..


using System;

//We need to include this namespace for file handling.
using System.IO;

namespace ConsoleApplication1
    class Program
        static void Main()
            string s;

            s =File.ReadAllText("ABC.TXT");

            Console.WriteLine("Content of file :\n"+s);


Content of file :
Hello , This is a sample program for writing text into file.

Note: In above program, we need to remember, when we use "File" class, System.IO namespace must be included in the program.

C# File Handling Programs »


Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.