手机
当前位置:查字典教程网 >编程开发 >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发邮件的几种方法汇总

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

将文本文件的内容或者文字保存成图片的方法介绍

asp.net动态加载自定义控件的方法

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

jQuery来获取RadioButtonList成员内容的方法

c#中实现文件拖放打开的方法

asp.net读取excel文件的三种方法示例

ASP.NET MVC3 实现全站重定向的简单方法

ewebeditor在.net的使用方法

精品推荐
分类导航