当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net StreamReader 创建文件

ASP.NET
细细品味ASP.NET(一)
细细品味ASP.NET(二)
细细品味ASP.NET(三)
细细品味ASP.NET(四)
细细品味ASP.NET(五)
用asp.net和xml做的新闻更新系统(1)
用asp.net和xml做的新闻更新系统(2)
用asp.net和xml做的新闻更新系统(3)
十天学会ASP.net(1)
十天学会ASP.net(2)
十天学会ASP.net(3)
十天学会ASP.net(4)
十天学会ASP.net(5)
十天学会ASP.net(6)
十天学会ASP.net(7)
十天学会ASP.net(8)
十天学会ASP.net(9)
十天学会ASP.net(10)
ASP.NET创建XML Web服务全接触(1)
ASP.NET创建XML Web服务全接触(2)

ASP.NET 中的 asp.net StreamReader 创建文件


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 146 ::
收藏到网摘: n/a

所用用到的命名空间:System.IO
我们所要创建的文件需要asp.net用户有一定的权限才可以!

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.Text;
usingSystem.IO;
namespacenew_app
{
///<summary>
///myxml的摘要说明。
///</summary>
publicclassmyxml:System.Web.UI.Page
{
privateconststringFILE_NAME="d:\\MyFile.txt";
privatevoidPage_Load(objectsender,System.EventArgse)
{
//在此处放置用户代码以初始化页面
write_file(FILE_NAME);
}

//一个创建文件的方法、并在文件里输入内容
publicvoidwrite_file(stringFILE_NAME)
{
if(File.Exists(FILE_NAME))
{
Console.WriteLine("{0}alreadyexists.",FILE_NAME);
return;
}
StreamWritersr=File.CreateText(FILE_NAME);
sr.WriteLine("这是我的第一个程序.");
sr.WriteLine("byzixian2005");
sr.Close();
}


#regionWeb窗体设计器生成的代码
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}