Jump to content

Using StreamWriter to put text from RichTextBox to .txt file

- - - - -

  • Please log in to reply
1 reply to this topic

#1
biscuits

biscuits

    Newbie

  • Members
  • Pip
  • 8 posts
Ok I need to write text that is in a RichTextBox into my text file so far I have managed to achieve this, BUT when it writes all the text to the .txt file it puts it all on one line, I need it to put the text on separate lines inside the .txt file. Here's my code so far:


{

            StreamWriter writer2 = new StreamWriter(@"C:\Users\Alex\Documents\Visual Studio 2010\Projects\MealDeliverySystem\orders.txt");

            writer2.Write(richTextBox1.Text);

            writer2.Close()

}


Posted Image
this is what my form looks like, notice how each bit of text goes on a separate line? thats how I want it to look inside my .txt file.

Any help is much appreciated, Thanks.

#2
anotheruser

anotheruser

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
I don't know what causes that problem but you could split the text into separate strings with "\n" as the parameter that signals where to make a cut. Then just cycle through the results and use writer2.WriteLine(i) on each of them.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users