• 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;

  • 相关阅读:
    01. 容器技术
    02. 关于 docker
    MAUI + MVVM + SIEMENS 跨平台应用实战
    从单例谈doublecheck必要性,多种单例各取所需
    git创建远程分支
    fabric peer节点账本验证器相关代码解读
    git 忽略 .idea文件
    Machine Learning With Go 第4章:回归
    一个恢复CSI挂载信息的解决方法
    使用kubeseal加密和管理k8s集群的secret
  • 原文地址:https://www.cnblogs.com/12go/p/2138015.html
Copyright © 2020-2023  润新知