c# get file as string code example
Example 1: c# read all text from a file
using (StreamReader streamReader = new StreamReader(path_name, Encoding.UTF8))
{
contents = streamReader.ReadToEnd();
}
Example 2: c# read file store in String
using System;
using System.IO;
public class Example
{
public static void Main()
{
string fileName = @"C:\some\path\file.txt";
string text = File.ReadAllText(fileName);
Console.WriteLine(text);
}
}