• asp.net更改文件夹名称及新建文件夹及删除文件夹


    if (Directory.Exists(oldPath))
                {

                    Directory.Move(oldPath, path);

                    if (OADBHelper.GetInt(sql) > 0)
                    {
                        Response.Write("<script>alert('更新成功!');</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('更新失败!');</script>");
                    }

                }
                else
                {

                    Response.Write("<script>alert('更新失败!');</script>");
                }

    }

    如果遇到此种情况:用Directory.Move移动文件夹改名是报错路径拒绝访问。

    最简单的,你尝试下移动文件夹改名时,在计算上直接操作。不用代码。看看是不是访问也被拒绝。
    如果拒绝,说明本身文件夹存在冲突,拒绝访问。

    一般都是这样的情况引起的。结束一些占用的进程等

    采用Directory.Exists方法
    string path=Server.MapPath("/file");
    if(!Directory.Exists(path))
    {
    Directory.CreateDirectory("path");
    }
    if(Directory.Exists(path))
    {
    Directory.Delete(path,true); //true为递归删除子文件内容
    }

    此类使用的命名空间using System.IO;

  • 相关阅读:
    python-阿里镜像源-pip
    python-Web-django-图形验证
    markdown-博客编辑
    python-爬虫-史书典籍
    python-爬虫-requests
    python-Web-项目-svn和git
    python-Web-数据库-Redis
    Codeforces Round #617 (Div. 3) A~D
    Educational Codeforces Round 81 (Rated for Div. 2)
    Codeforces Round #609 (Div. 2) A到C题
  • 原文地址:https://www.cnblogs.com/12go/p/2138015.html
Copyright © 2020-2023  润新知