C#: Prepending to beginning of a file

This works for me, but for small files. Probably it’s not a very good solution otherwise.

string currentContent = String.Empty;
if (File.Exists(filePath))
{
    currentContent = File.ReadAllText(filePath);
}
File.WriteAllText(filePath, newContent + currentContent );

Leave a Comment