Convert a text file to uppercase Learn programming C#

Lesson:

File Management


Exercise:

Convert a text file to uppercase


Objetive:

Write a program to read a text file and dump its content to another file, changing the lowercase letters to uppercase.

You must deliver only the ".cs" file, with you name in a comment.


Code:

using System;
using System.IO;
namespace FileLowerCaseToUpperCase
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter name file: ");
            string fileName = Console.ReadLine();

            if (File.Exists(fileName))
            {
                StreamReader fileRw = File.OpenText(fileName);
                StreamWriter fileWr = File.CreateText(fileName + ".dat");
                string line;
                do
                {
                    line = fileRw.ReadLine();
                    if (line != null)
                        fileWr.WriteLine(line.ToUpper());
                }
                while (line != null);
                fileRw.Close();
                fileWr.Close();
            }
        }
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.