Click here to Skip to main content
15,071,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void file_write()
        {
            string path = "C:\\Users\\Techsoft\\Desktop\\textbox\\text2";           
            string ext = ".txt";
            string fname = path + ext;
            
            
            FileInfo file1 = new FileInfo(fname);
            StreamWriter sw = file1.CreateText();
            sw.WriteLine(richTextBox1.Text);

            sw.Close();
        }

        private void file_read()
        {
            string path = "C:\\Users\\Techsoft\\Desktop\\textbox\\text";           
            string name = richTextBox1.Text;
            string ext = ".txt";
            string fname = path + name + ext;
            string readcontent;

            FileInfo file1 = new FileInfo(fname);

            StreamReader sr = new StreamReader(fname);
            readcontent = sr.ReadToEnd(); 	    
            sr.Close();
            richTextBox1.Text = readcontent;             
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            file_read();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            file_write();
        } 

output in new textfile created is "hello world"

but i want hello in one line and world in new line.. how? help
Posted
Updated 25-Feb-13 22:45pm
v2

try to add
C#
Environment.NewLine
to add new line.
   
Comments
navin ks 26-Feb-13 5:05am
   
code please
boogac 26-Feb-13 7:26am
   
while you are writing Hello World ,you can split your word ( Hello and World you get) and between them you can use Ahmad's code..You shouldnt rely on code everytime,just try your algorithms
try this.

C#
for (int i = 0; i < richTextBox1.Lines.Length; i++)
{
     sw.WriteLine(richTextBox1.Lines[i]);
}
   
Try this!
C#
sw.WriteLine(richTextBox1.Text+"\n");
   
Comments
navin ks 26-Feb-13 7:12am
   
no use @pedro
Pedro Minatel 26-Feb-13 8:14am
   
Please, be more specific! There's a ton of examples to try on the internet.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900