zoukankan      html  css  js  c++  java
  • asp.net如何判断服务器上的目录或文件是否存在

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

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

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

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

        [csharp] view plaincopy在CODE上查看代码片派生到我的代码片
         
        1. using System.IO;  // 还需要命名空间,别忘了  
        [csharp] view plaincopy在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 plaincopy在CODE上查看代码片派生到我的代码片
         
        1. <span style="font-size: 14px; line-height: 26px; ">System.IO.Directory.CreateDirectory(Server.MapPath("file"));   // 创建文件夹 </span>     
        [csharp] view plaincopy在CODE上查看代码片派生到我的代码片
         
        1. <span style="font-size: 14px; line-height: 26px; ">      System.IO.Directory.Delete(Server.MapPath("file"),true);//删除文件夹以及文件夹中的子目录,文件</span>  
        [csharp] view plaincopy在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

  • 相关阅读:
    CS231n 学习笔记(1) Image CLassification
    caffe-winsows封装成dll
    Nuget安装程序包源
    PCA降维demo
    AI方面的国际会议
    caffe solver
    caffe数据层
    一些有意思的技术博客
    js cookie 设置
    knockout.validation.js 异步校验
  • 原文地址:https://www.cnblogs.com/shangshen/p/3532648.html
Copyright © 2011-2022 走看看