在现有文本的新行中添加新字符串

时间:2011-10-05 21:38:15

标签: c#

我想打开一个文本,我已经输入了许多字符串,并且在所有行之后 我想创建一个新行并在信息中写入信息 关于我要编写的新行我从文本框中取出

//button open file
private void button4_Click(object sender, EventArgs e)
    {
        if(openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            label7.Text = openFileDialog1.FileName;
            textBox7.Text = File.ReadAllText(label7.Text);
        }
    }


    //button save file
    private void button5_Click(object sender, EventArgs e)
    {
        if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {

            File.WriteAllText(saveFileDialog1.FileName, textBox7.Text);
        }

    }

      //this is the add button
    private void button1_Click(object sender, EventArgs e)
       {

        string inValue1, inValue2, inValue3, inValue4, inValue5, inValue6;
        inValue1 = textBox1.Text;
        inValue2 = textBox2.Text;
        inValue3 = textBox3.Text;
        inValue4 = textBox4.Text;
        inValue5 = textBox5.Text;
        inValue6 = textBox6.Text;


        string result = (inValue1 + "," + inValue2 + "," + inValue3 + ","
            +inValue4+ "," +inValue5 + "," +inValue6);
        //File.WriteAllText("C:\\text.txt", textBox1.Text);
        System.IO.File.WriteAllText(@"C:\Users\v\Desktop\text.txt", result);
    }

1 个答案:

答案 0 :(得分:4)

File.AppendAllText(filename, "new line of text");

或者,如果文件目前没有以换行符结束:

File.AppendAllText(filename, Environment.NewLine + "new line of text");