Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

read from a richtextbox and write to the text file

Posted on 2009-04-26
2
Medium Priority
?
237 Views
Last Modified: 2012-05-06
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();
0
Comment
Question by:IzzyTwinkly
  • 2
2 Comments
 
LVL 39

Accepted Solution

by:
abel earned 1600 total points
ID: 24236670
This line:

string myPath = @"C:\\MyFolder" + "myTextFile.txt";
is probably not what you want it to be. It goes to C:\\MyFolder instead of C:\MyFolder. Try this instead:

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

The reason that you System.String[] is because you are converting the Lines array to a string. Try:






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[i]);    
}
sw.Close();

Open in new window

0
 
LVL 39

Expert Comment

by:abel
ID: 24236677
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

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month21 days, 3 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question