ApprenticeHacker ApprenticeHacker - 1 year ago 92
C# Question

Easiest way to read from and write to files

There are a lot of different ways to read and write files (text files, not binary) in C#.

I just need something that is easy and uses the least amount of code, because I am going to be working with files a lot in my project. I only need something for

since all I need is to read and write

Answer Source



Could not be simpler...

MSDN examples:

// Create a file to write to. 
string createText = "Hello and Welcome" + Environment.NewLine;
File.WriteAllText(path, createText);

// Open the file to read from. 
string readText = File.ReadAllText(path);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download