Copy Code code 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 necessary.
Namespace Aspnetcs
{
<summary>
Summary description of the 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 ()//is the above code, if the Response.WriteFile method, although can read TXT file content, but can not display the segmented format
Place user code here to initialize page
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
protected void Button1_Click (object sender, System.EventArgs e)
{
session["Name"]=textbox1.text;
Response.Redirect ("webform2.aspx");
}
}
}