asp.net StreamReader 创建文件

所用用到的命名空间: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
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晓梦庄子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值