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

ASP.NET
自定义控件(支持模板)
自定义控件(模板+数据绑定)
自定义控件(可以动态加载用户控件)
在代码隐藏中遍历当前页的所有控件
关于C#调用Office Web Components绘图的问题
利用Visual C#打造一个平滑的进度条
[VB] 防止程序运行多个实例
Visual Studio.Net 快捷键表
WinForm中ToolBar与TabControl的一些事件写法(C#)
【翻译】Managed DirectX(第六章)
利用.NET语言开发自己的脚本语言(一)
自动改变CheckBoxList选择项目的背景颜色
vb.net中windows服务的创建
BASE64编码规则及C#实现
.net中判断该应用程序是否已经启动,防止重复启动
XML Web Service 数据交换
开发花絮:一个DataList的ItemCommand事件意外
Snake.Net中的ORM(二)
ASP操作XML数据小结
可用来显示空值的时间选择控件4

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 163 ::
收藏到网摘: 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
}
}