StavrosFlatline
StavrosFlatline

Reputation: 13

Using StreamWriter and StreamReader in a Windows Application

I could use some help as I can't seem to work this out but I'm creating a c# windows application and I need to read and write from files. I've mostly got it working as I want but when I write to the file it adds this extra text "System.Windows.Forms.RichTextBox, Text:" and then displays what I want it to.

Is there a way to just input and display the text I'm actually writing rather than adding the additional properties of the text box.

Any help would be massively appreciated.

My code for adding text is

        {
            using (StreamWriter sw = new StreamWriter(@"C:\Users\bin\Debug\net6.0-windows\ManagerStock.txt"))
            {
                sw.WriteLine(managerAddtxt);
            }
        }

and my code for reading is

        {
            using (StreamReader re = new StreamReader(@"CC:\Users\bin\Debug\net6.0-windows\ManagerStock.txt"))
            {
                while (!re.EndOfStream) 
                {
                    managerStocktxt.AppendText(re.ReadLine());
                }
            }
        }

Upvotes: 1

Views: 185

Answers (1)

EddieLotter
EddieLotter

Reputation: 374

You're getting that because you are writing an object to the stream.

Change your code to the following and you will get what you expect:

sw.WriteLine(managerAddtxt.Text);

Upvotes: 3

Related Questions