0
if (infile != null)
            {
                infile.Close();
            }
            if (reader != null)
            {
                reader.Close();
            }

            //Creating a File Stream object to Open a file called FILENAME for writing

            outfile = new FileStream(FILENAME, FileMode.Append, FileAccess.Write);

            //Creating a Stream Writer with the outFile File Stream object
            writer = new StreamWriter(outfile);

            writer.Write("Income : $");
            writer.WriteLine(Convert.ToString(Income));
            writer.Write("Less: Expense : $");
            writer.WriteLine(Convert.ToString(Expenses));
            writer.Write("Add Trade : $");
            writer.WriteLine(Convert.ToString(trade));
            writer.Write("Add Other Income : $");
            writer.WriteLine(Convert.ToString(addotherincome));
            writer.Write("Less Donation : $");
            writer.WriteLine(Convert.ToString(donation));
            writer.Write("Less Interest : $");
            writer.WriteLine(Convert.ToString(interest));
            writer.Write("Less Dividends : $");
            writer.WriteLine(Convert.ToString(dividends));
            writer.Write("Less Parenthood Rebates : $");
            writer.WriteLine(Convert.ToString(parenthood));
            writer.Write("Less Employment Expenses : $");
            writer.WriteLine(Convert.ToString(employment_expenses));
            writer.Write("Less NS man Relief : $");
            writer.WriteLine(Convert.ToString(nsman));
            writer.Write("Earned Income Relief : $");
            writer.WriteLine(Convert.ToString(e_incomerelief));
            writer.Write("Chargable Income : $");
            writer.WriteLine(Convert.ToString(chargeableincome));
            writer.Write("Personal Relief : $");
            writer.WriteLine(Convert.ToString(personal_relief));
            writer.Write("Tax Payable : $");
            writer.WriteLine(Convert.ToString(Tax));
            


            outfile.Seek(0, SeekOrigin.End);

            writer.Close();
            outfile.Close();

this is my code to declare the writer.
but how do i get those information in the lines and read it into a textbox... im using this code...

//Creating a File Stream object to Open a file called FILENAME for writing

            infile = new FileStream(FILENAME, FileMode.Open, FileAccess.Read);

            //Creating a Stream Writer with the outFile File Stream object
            reader = new StreamReader(infile);

            try
            {
                recordIn = reader.ReadLine();
                RecArray = recordIn.Split(DELIM);
                income_tb.Text = RecArray[0];
                expense_tb.Text = RecArray[1];

but it can only read the first line...
HELP

Edited by __avd: Added [code] tags.

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by jonsca
1

What does DELIM consist of?

The reason you are getting one line is your ReadLine is not in a loop. You're going to have to read in a line, split it in two, drop the label, place the data in the array and move to the next line.

Votes + Comments
read in one line, then complain that you only get one line...aah newbies, whatever shall we do with you :p
1

You can all the lines by using a while loop and checking for EndOfStream bool:

while(!reader.EndOfStream)
{
    line = reader.ReadLine();
}
1

You can also read all the lines in one go in to a string array without having to worry about creating a StreamReader.

string[] lines = File.ReadAllLines(FILENAME);
0

so if i use string[]lines = File.ReadAllLines(FILENAME);

all my textbox will display the arrays accordingly?

0

You'll still need to split the strings. ReadAllLines (which I think is new to .NET 4.0) just avoids having to use a loop. You'll end up with one string per line, I believe.

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.