asp.net如何判断服务器上的目录或文件是否存在

    • asp.net判断服务器上的目录或文件是否存在!(实例)

       

      // ======================================================= 【判断文件是否存在】

       

      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. using System.IO;  // 还需要命名空间,别忘了  
      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. if (System.IO.File.Exists("c:\\aaa.txt"))    // 注意双引号路径应为双斜杠  
      2. {  
      3.     //########## 有aaa.txt文件!  
      4. }  

       

      // ======================================================= 【判断目录是否存在】

       

      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. using System.IO;  // 还需要命名空间,别忘了  
      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. if (System.IO.<span style="font-size: 14px; line-height: 26px; ">Directory</span>.Exists("c:\\aaa"))    // 注意双引号路径应为双斜杠  
      2. {  
      3.     //########## 有aaa文件夹!  
      4.       
      5. }  
       
      // ========================================================= 【创建删除等,网上找的,没测试】
      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. <span style="font-size: 14px; line-height: 26px; ">System.IO.Directory.CreateDirectory(Server.MapPath("file"));   // 创建文件夹 </span>     
      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. <span style="font-size: 14px; line-height: 26px; ">      System.IO.Directory.Delete(Server.MapPath("file"),true);//删除文件夹以及文件夹中的子目录,文件</span>  
      [csharp]  view plain copy 在CODE上查看代码片 派生到我的代码片
       
      1. <span style="font-size: 14px; line-height: 26px; "><span style="font-size: 14px; line-height: 26px; ">      Directory.Create(Server.MapPath("~/Back/Data.xml"));//创建该文件</span>  
      2. </span>  

       

       

      转载自:http://www.hello-code.com/blog/asp.net/201312/2484.html

转载于:https://www.cnblogs.com/shangshen/p/3532648.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值