Copy codeThe Code is as follows: using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using System. IO; \ This is required
Namespace aspnetcs
{
/// <Summary>
/// Summary of WebForm1.
/// </Summary>
Public class WebForm1: System. Web. UI. Page
{
Private void Page_Load (object sender, System. EventArgs e)
{
If (! File. Exists (MapPath ("weather.txt ")))
{
Console. WriteLine ("{0} does not exist.", MapPath ("weather.txt "));
Return;
}
StreamReader sr = new StreamReader (MapPath ("weather.txt"), System. Text. Encoding. Default );
String input = sr. ReadToEnd ();
Sr. Close ();
Input = input. Replace ("\ r \ n", "<br>"). Replace ("\ n", "<br> ");
Response. Write (input );
Response. End (); // This is the code above. If the Response. WriteFile method is used, although the txt file content can be read, the segment format cannot be displayed.
// Place user code here to initialize the page
}
# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
Protected void button#click (object sender, System. EventArgs e)
{
Session ["name"] = TextBox1.Text;
Response. Redirect ("WebForm2.aspx ");
}
}
}