Read content from file using C#

using System;
using System.IO;

public class FileOp {
    public static string GetFileContent() {
        string contentString = System.IO.File.ReadAllText("C:\\filename.json");
        return contentString;

If you want to read data from a file, you can use ReadAllText(filepath) in C# which will return you the text content which exist on the file in string format. 

Use System and System.IO to make it work. In the example we are getting data from a file which exist on location "C:\\filename.json". It will return data that is written on the file.

Was this helpful?