Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a problem:
String text = File.ReadAllText (@ "C: \ Test.txt");
String [] parts = text.Split (new String [] {"/ / n"}, StringSplitOptions.RemoveEmptyEntries);
            
richTextBox1.Text = parts [0];
richTextBox2.Text = parts [1];

I want to save the text file after changing into test.txt
After running the application, I have written text on the richTextBox2 and richTextBox1. How can I put the content of richTextBox1 into parts[0], and richTextBox2 into part[1]? Thanks!
Posted
Updated 20-Dec-10 21:29pm
v3
Comments
Wild-Programmer 21-Dec-10 3:13am    
Please clarify the question. do you wish to reassign the array with text box values??
Khaniya 21-Dec-10 3:24am    
what do mean by this?
"/ / n"

If it is separation string then it is OK
above code will run

Hi, try this:
C#
private void button1_Click(object sender, EventArgs e)
{
  File.WriteAllText(@"C:\Test.txt", richTextBox1.Text + "/ / n" + richTextBox2.Text);
}


This saves the content of the richtextboxes to the C:\Test.txt file when button1 is clicked(you should use your own event handler).
 
Share this answer
 
v2
XML
<form id="form1" runat="server">
    <div>
        <asp:Button Text="Read File" runat="server" ID="btnReadTextFile"
            onclick="btnReadTextFile_Click" /><br />
        Text 1 :<asp:TextBox runat="server" ID="input1" />  <br />
        Text 2 <asp:TextBox runat="server" ID="input2" />  <br />
        <asp:Button Text="Save" runat="server" ID="btnSave" onclick="btnSave_Click" />
    </div>
    </form>



C#
protected void btnReadTextFile_Click(object sender, EventArgs e)
     {
         String text = File.ReadAllText(@"D:\\Test.txt");
         String [] parts = text.Split (new String [] {"\n"}, StringSplitOptions.RemoveEmptyEntries);
         input1.Text = parts [0];
         input2.Text = parts [1];
     }
     protected void btnSave_Click(object sender, EventArgs e)
     {
         File.WriteAllText(@"D:\\Test.txt", input1.Text + "\n" + input2.Text);
     }
 
Share this answer
 

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