Click here to Skip to main content
15,663,341 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
i want to write the following information to a file.....a stream file,,,,,,
Console.WriteLine("________________Student information______________");
                   Console.WriteLine("Enter student name ");
                   Firstname = Console.ReadLine();
                   Console.WriteLine("Enter the Surname ");
                   Surname = Console.ReadLine();
                   Console.WriteLine("Enter student date of birth");
                   DOB = DateTime.Parse(Console.ReadLine());
                   Console.WriteLine("Enter student Gender either F/M ");
                   Gender = char.Parse(Console.ReadLine());
                   Console.WriteLine("Total fees paid N$");
                   Total_Fees_paid = double.Parse(Console.ReadLine());
                   amount_owed = totalcost - Total_Fees_paid;
                   Console.WriteLine("__________NEXT OF KIN__________");
                   Console.WriteLine("Enter next of kin/parent/gurdian's Title ");
                   nTitle = Console.ReadLine();
                   Console.WriteLine("Enter next of kin/parent/gurdian's Name ");
                   nFirstname = Console.ReadLine();
                   Console.WriteLine("Enter next of kin/parent/gurdian's Surname ");
                   nsurname = Console.ReadLine();
                   Console.WriteLine("Enter next of kin/parent/gurdian's date of birth");
                   nDOB = DateTime.Parse(Console.ReadLine());
                   Console.WriteLine("Enter next of kin/parent/gurdian's Occupation");
                   nOccupation = Console.ReadLine();
                   Console.WriteLine("Enter next of kin/parent/gurdian's Desgnation");
                   nDesgination = Console.ReadLine();

What I have tried:

Streamwriter wr = new Streamwriter;
Updated 26-Apr-16 4:56am
Sergey Alexandrovich Kryukov 26-Apr-16 10:52am    
By the way, what you have "tried" won't compile. C# is case-sensitive, you know... :-)
What's wrong with just reading original MSDN documentation?
ZurdoDev 26-Apr-16 10:54am    
There are tons of examples online of using a StreamWriter. However, you can also use File.WriteAllText() which is very easy to do.

How to: Write Text to a File[^]

However you'd be better storing the data in a class with properties that hold the data being input, and serialise\deserialise that class.

Basic Serialization[^]
Share this answer
Member 12485384 26-Apr-16 10:59am    
using (StreamWriter outputFile = new StreamWriter(mydocpath + @"\WriteLines.txt")) {
foreach (string line in lines)

using is underline so the code will give errors.
StreamWriter wr = new StreamWriter(@"c:\file.txt");
...etc for the rest of the lines...

If you want to append to the file everytime then use: StreamWriter wr = new StreamWriter(@"c:\file.txt", true);
Share this answer
Member 12485384 26-Apr-16 11:23am    
its not working in MVS 2012
WiganLatics 26-Apr-16 11:27am    
Well is it compiling? Or is it crashing when you run it? What's the error message? And do you have permissions to write to the folder you are trying to write to?
Member 12485384 26-Apr-16 13:50pm    
should i send you the official pdf.....with the questions

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900