在文本框中添加新行

时间:2014-06-01 04:20:14

标签: c# asp.net arrays streamwriter

在文本文件中,它打印在一个新行上但是当它显示在文本框中时,它在同一行是否有任何想法如何解决这个问题?

   {    
      string[] justJeansArray = new string[10];

protected void Page_Load(object sender, EventArgs e)
{


    string filepath = Server.MapPath("~") + "//app_data\\justJeansBlog.txt";
    StreamReader sr = new StreamReader(filepath);
    string justJeansstring = sr.ReadToEnd();
    string[] justJeansArray = justJeansstring.Split('\n');

     for (int i = justJeansArray.Length - 1; i > justJeansArray.Length - 6; i--)
    {
        blogTB.Text += justJeansArray[i] + "\n\n";
    }

    sr.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{

    StreamWriter sw = new StreamWriter(Server.MapPath("~") +    "//app_data\\justJeansBlog.txt", true);
    sw.WriteLine(messageTB.Text);
    sw.Close();


    Response.Redirect("justJeans.aspx");
}

}

1 个答案:

答案 0 :(得分:1)

启用文本框的TextMode属性为MultiLine以允许此操作:

blogTB.TextMode = TextBoxMode.MultiLine;
blogTB.Rows = 10;