Read a file into a string in C#
<p>I am trying to read a file into a string which then I will send to another application.</p>

<pre><code>using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Create an instance of StreamReader to read from a file.
                // The using statement also closes the StreamReader.
                using (StreamReader sr = new StreamReader("c:\text.txt"))
                {
                    string line;

                    // Read and display lines from the file until 
                    // the end of the file is reached. 
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                }
            }
            catch (Exception e)
            {

                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
    }
}
</code></pre>

<p>I am getting the error:  </p>

<pre><code>The file could not be read:
Could not find file 'c:\users\andymarkmn\documents\visual studio 2015\Projects\FileApplication\FileApplication\bin\Debug\text.txt'.
</code></pre>

<p>I have tried putting the file in bin debug folders as well.</p>

<p>How to make sure the code works ?</p>

<p><strong>EDIT:  As suggested, I tried using the different ways.</strong></p>

<pre><code>using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FileApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string filepath = "c:\\text.txt";

            try
            {
                string lines = File.ReadAllText(filepath);
                Console.Write(lines);
            }
            catch (Exception e)
            {

                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            Console.ReadKey();
        }
    }
}
</code></pre>

<p>I still get the error:</p>

<pre><code>The file could not be read:
Could not find file 'c:\text.txt'.
</code></pre>