手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >读取TXT文件内容的方法
读取TXT文件内容的方法
摘要:复制代码代码如下:usingSystem;usingSystem.Collections;usingSystem.ComponentMode...

复制代码 代码如下:usingSystem;

usingSystem.Collections;

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Web;

usingSystem.Web.SessionState;

usingSystem.Web.UI;

usingSystem.Web.UI.WebControls;

usingSystem.Web.UI.HtmlControls;

usingSystem.IO;这是必须的

namespaceaspnetcs

{

///<summary>

///WebForm1的摘要说明。

///</summary>

publicclassWebForm1:System.Web.UI.Page

{

privatevoidPage_Load(objectsender,System.EventArgse)

{

if(!File.Exists(MapPath("weather.txt")))

{

Console.WriteLine("{0}doesnotexist.",MapPath("weather.txt"));

return;

}

StreamReadersr=newStreamReader(MapPath("weather.txt"),System.Text.Encoding.Default);

Stringinput=sr.ReadToEnd();

sr.Close();

input=input.Replace("rn","<br>").Replace("n","<br>");

Response.Write(input);

Response.End();//就是这上面的代码,如果用Response.WriteFile方法,虽然能读出txt文件内容,却不能显示分段格式

//在此处放置用户代码以初始化页面

}

#regionWeb窗体设计器生成的代码

overrideprotectedvoidOnInit(EventArgse)

{

//

//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。

//

InitializeComponent();

base.OnInit(e);

}

///<summary>

///设计器支持所需的方法-不要使用代码编辑器修改

///此方法的内容。

///</summary>

privatevoidInitializeComponent()

{

this.Load+=newSystem.EventHandler(this.Page_Load);

}

#endregion

protectedvoidButton1_Click(objectsender,System.EventArgse)

{

Session["name"]=TextBox1.Text;

Response.Redirect("WebForm2.aspx");

}

}

}

【读取TXT文件内容的方法】相关文章:

asp.net获取HTML表单File中的路径的方法

将datagrid控件内容输出到excel文件

asp.net水晶报表参数字段在代码中赋值的方法

ASP.Net下载大文件的实现方法

ASP.NET 运行.bat文件的实现方法

asp.net实现C#绘制太极图的方法

ASP.NET实现推送文件到浏览器的方法

asp.net中List的使用方法

ASP.Net中防止刷新自动触发事件的解决方案

ASP.NET抓取网页内容的实现方法

精品推荐
分类导航