Code:
public static void WriteToFile(string stringToWrite)
{
TextWriter tw = new StreamWriter("FileName", true); //save AND append, don't rewrite it each stream write - false rewrites
tw.WriteLine("[" + DateTime.Now + "]: " + stringToWrite);
tw.Close();
}
public static string ReadFromFile(string fileName)
{
StreamReader reader = new StreamReader(fileName);
string file = reader.ReadToEnd();
reader.Close();
return file;
}
Here's a snippet from one of my projects.
For parsing inside a text file, you probably want to use try-catch-finally and always close the file (just as good practise). You should use Substring to cut away at your strings (since the streamreader goes line by line it's very easy just to use IndexOf in whatever format you want (such as Press|x|y|z or p|x|y|z or whatever). If you want something advanced (or just to learn), look into regular expressions.