讀取TXT文件內(nèi)容的方法
更新時間:2006年10月26日 00:00:00 作者:
復制代碼 代碼如下:
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;\\這是必須的
namespace aspnetcs
{
/// <summary>
/// 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();//就是這上面的代碼,如果用Response.WriteFile方法,雖然能讀出txt文件內(nèi)容,卻不能顯示分段格式
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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");
}
}
}
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;\\這是必須的
namespace aspnetcs
{
/// <summary>
/// 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();//就是這上面的代碼,如果用Response.WriteFile方法,雖然能讀出txt文件內(nèi)容,卻不能顯示分段格式
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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");
}
}
}
相關文章
ASP.NET web.config 配置節(jié)點詳解
這篇文章主要介紹了ASP.NET web.config 節(jié)點的配置,講解的非常詳細,需要的朋友可以參考下。2016-06-06學會區(qū)分Visual Studio 2005,Visual Studio 2005 Team System和MSDN P
學會區(qū)分Visual Studio 2005,Visual Studio 2005 Team System和MSDN Premium 訂閱的各個版本...2007-01-01.Net創(chuàng)建型設計模式之工廠方法模式(Factory?Method)
這篇文章介紹了.Net設計模式之工廠方法模式(Factory?Method),文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05asp.net實例代碼protected override void Render(HtmlTextWriter wri
把最終要輸出的html壓縮后再輸出和最終輸出前先存為html文件,如果發(fā)布最新信息了,可以打開一次default.aspx,然后他又會生成一次html2008-08-08