动态创建文本文件并写入数据 避免正由另一进程使用,因此该进程无法访问该文件。的问题...

首先

 

 
  
1 string filename = this .txtname.Text.Trim();
2 string filecontent = this .txtcontent.Text.Trim();
3
4 string FileDir = Server.MapPath( " ~/Files " );
5 if ( ! Directory.Exists(FileDir)) //判断是否存在此文件夹
6 {
7 Directory.CreateDirectory(FileDir);
8 }
9 string FileTxtPath = " ~/Files/ " + filename + " .txt " ;
10 FileTxtPath = Server.MapPath(FileTxtPath);
11 if ( ! File.Exists(FileTxtPath))//判断是否存在此文本文件
12 {
13 FileStream _file = new FileStream(FileTxtPath, FileMode.Create, FileAccess.ReadWrite);
14 _file.Dispose();//非常重要哦,创建完文本文件要释放资源的,否则就会报错了
15 using (StreamWriter SW = File.CreateText(FileTxtPath))
16 {
17 SW.Write(filecontent);
18 SW.Dispose();
19
20 Server.ClearError();
21 }
22
23 }

转载于:https://www.cnblogs.com/zlzly/archive/2011/02/26/1965993.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值