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

  • 相关阅读:
    VBA代码分行
    Excel VBA 操作 Word(入门篇)
    Excel公式与函数——每天学一个
    VBA二次学习笔记(1)——文件操作
    架构探险——学到的知识
    架构探险——搭建框架
    文件下载
    文件上传
    jdbc中的细节
    json
  • 原文地址:https://www.cnblogs.com/shangshen/p/3532648.html
Copyright © 2011-2022 走看看