Writing Output to A File in C# 2005
<p>i have created a marksheet program in c# 2005, its working fine it is taking input and showing the output by using the below code. now if i want that the output of this program is also copied in a new file located in my C or any drive. what should i do? i tried IO.StreamWriter but its not working. </p>

<pre><code>using(System.IO.TextWriter writer = System.IO.File.CreateText(@"C:\1.txt"))
        {
Console.WriteLine("\t\tMarksheet - Prislogix Public School");
                Console.Write("\n\nStudent Name : " + name);
                Console.Write("\nClass : " + cls);
                Console.Write("\nRoll Number : " + roll);
                Console.Write("\n\nSubject\t\tObtained Marks\t\tTotal Marks");
                Console.Write("\n\nChemistry\t\t" + chem + "\t\t75");
                Console.Write("\nEnglish\t\t\t" + eng + "\t\t100");
                Console.Write("\nCalculus\t\t\t" + urd + "\t\t100");
                Console.Write("\nDiscrete\t\t\t" + sin + "\t\t75");
                Console.Write("\nMathematics\t\t" + mat + "\t\t100");
                Console.Write("\nPhysics\t\t\t" + phy + "\t\t75");
                Console.Write("\nComputer\t\t" + comp + "\t\t100");
                Console.Write("\nMethods\t\t" + isl + "\t\t50");
                float tot = chem + eng + urd + sin + mat + phy + comp + isl;
                Console.Write("\n\n\t\t\tTotal Obtained Marks : " + tot + "\tOut Of 625");
                float per;
                per = (tot / 625) * 100;
                Console.Write("\n\t\t\tPercentage : " + per + "%");
                if (per &lt; 49 &amp;&amp; per &gt; 40)
                {
                    Console.Write("\n\t\t\tFAILED!");
                }
                if (per &lt;= 59 &amp;&amp; per &gt;= 50)
                {
                    Console.Write("\n\t\t\tGrade : C");
                }
                if (per &lt;= 69 &amp;&amp; per &gt;= 60)
                {
                    Console.Write("\n\t\t\tGrade : B");
                }
                if (per &lt;= 79 &amp;&amp; per &gt;= 70)
                {
                    Console.Write("\n\t\t\tGrade : A");
                }
                if (per &lt;= 89 &amp;&amp; per &gt;= 80)
                {
                    Console.Write("\n\t\t\tGrade : A+");
                }
                if (per &lt;= 100 &amp;&amp; per &gt;= 90)
                {
                    Console.Write("\n\t\t\tGrade : A-ONE");
                }
            }
}
            Console.ReadLine();
</code></pre>
