Read Text File in ( or

Read Text File in ( or C#-Read-Text-File

Reading text file using C# or is one of the basic programming construct and I bet you all had done it. Here are the examples which reads text file.

C# read file example

using System;
using System.IO;
namespace Csharp.ReadFile.Example
class Program
static void Main(string[] args)
string filePath = @"C:\xxx";
if (!File.Exists(filePath))
filePath  = filePath + @"\" + "REadme.txt";
FileStream fs = new FileStream(filePath, FileMode.Open);
StreamReader reader = new StreamReader(fs);
This is first line
This is second line
This is third line
Imports System.IO
Namespace Csharp.ReadFile.Example
Class Program
Private Shared Sub Main(args As String())
Dim filePath As String = "C:\xxx"
If Not File.Exists(filePath) Then
filePath = filePath & "\" & "REadme.txt"
Dim fs As New FileStream(filePath, FileMode.Open)
Dim reader As New StreamReader(fs)
End If
End Sub
End Class
End Namespace