Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Viewing and updating file content in C#

We can view the content of a file and update it with new content.

using System;
using System.IO;

namespace forgetCode
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "D:\\test.txt";
            if (File.Exists(path))
            {
                string content = File.ReadAllText(path);
                Console.WriteLine("Current content of file:");
                Console.WriteLine(content);
            }

            Console.WriteLine("\nPlease enter the new content");
            string newContent = Console.ReadLine();

            File.WriteAllText(path, newContent);

        }
    }
}


Output:
The content of file will be shown.
The user can enter new content and it will be written to the same file.

..