Link to home
Start Free TrialLog in
Avatar of IzzyTwinkly
IzzyTwinklyFlag for United States of America

asked on

read from a richtextbox and write to the text file

Hi,

I am trying to read line by line from a richtextbox and write it to the text file.
but the contents on the text files are like
System.String[]
System.String[]
System.String[]
System.String[]
System.String[]
...
What is going on here?  How should I fix this issue?
My codes are follow:

string myPath = @"C:\\MyFolder" + "myTextFile.txt";

StreamWriter sw = File.CreateText(myPath);
int count = myRichTbx.Lines.Length;

for (int i = 0; i < count; i++)
{
      sw.WriteLine(myRichTbx.Lines.ToString());    
 }
sw.Close();
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It's even easier if you use foreach:

string myPath = @"C:\MyFolder\" + "myTextFile.txt";
 
StreamWriter sw = File.CreateText(myPath);
 
for (string sLine in myRichTbx.Lines)
{
      sw.WriteLine(sLine);    
}
sw.Close();

Open in new window