Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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());
                }
            }
        }

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading