Search code snippets, questions, articles...

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.

Search Index Data (The code snippet can also be found with below search text)

get file content using c#
Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet