asp.net读取磁盘文件、删除实例代码

复制代码 代码如下:


    protected void ReadFile()     //读取文件夹,文件
    {
        string savePath = @"common";
        StringBuilder outstring = new StringBuilder();
        string absSavePath = Server.MapPath(savePath);
        string[] Directorys = Directory.GetDirectories(absSavePath + @"https://www.jb51.net/" + Page.User.Identity.Name);
        //for (int i = 0; i < Directorys.Length; i++)
        //{
        //    Response.Write(Directorys[i] + " <br/ >");
        //}
        //Response.Write("Directorys count:" + Directorys.Length + "个  <br/ >--------- <br >");
        string[] Files = Directory.GetFiles(absSavePath + @"" + Page.User.Identity.Name, "*");
        outstring.Append("<ul>");
        for (int i = 0; i < Files.Length; i++)
        {
            if (Path.GetFileName(Files[i]) != "Thumbs.db")
            {
                outstring.Append("<li><img src=https://www.jb51.net/"common/" + Path.GetFileName(Files[i]) + "https://www.jb51.net/" style=https://www.jb51.net/"width:100px;height:100px;/" /><br/><input type=https://www.jb51.net/"checkbox/" value=https://www.jb51.net/"common/" + Path.GetFileName(Files[i]) + "https://www.jb51.net/" name=https://www.jb51.net/"picname/" onclick=https://www.jb51.net/"getpicid();/" id=https://www.jb51.net/"imgid" + i.ToString() + "https://www.jb51.net/" /><label for=https://www.jb51.net/"imgid" + i.ToString() + "https://www.jb51.net/">" + Path.GetFileName(Files[i]) + "</label></li>");
            }
        }
        outstring.Append("</ul>");
        Response.Write(outstring.ToString());
    }

//删除文件
        string[] strpicname = Request["imgids"].Split(new char[] { ',' });
        for (int i = 0; i < strpicname.Length; i++)
        {
            File.Delete(Server.MapPath(strpicname[i].ToString()));
        }


复制代码 代码如下:


//循环遍历复选框
<script language="javascript" type="text/javascript" defer="defer">
    var imgnum = document.getElementsByTagName("input");
    var imgids = "";
    function getpicid()
    {
        document.getElementById("hidimgid").value = "";
        for (var i=0;i<imgnum.length;i++)
        {
            if ( imgnum[i].type == "checkbox" && imgnum[i].name == "picname" && imgnum[i].checked)
            {
                imgids += imgids == "" ? imgnum[i].value : "," + imgnum[i].value;
            }
        }
        document.getElementById("hidimgid").value = imgids;
    }
    </script>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgwpz.html