服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - ASP.NET教程 - asp.net读取磁盘文件、删除实例代码

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

2019-11-20 13:45asp.net教程网 ASP.NET教程

这篇文章介绍了asp.net读取磁盘文件、删除实例代码,有需要的朋友可以参考一下

代码如下:

    protected void ReadFile()     //读取文件夹,文件 
    { 
        string savePath = @"common"; 
        StringBuilder outstring = new StringBuilder(); 
        string absSavePath = Server.MapPath(savePath); 
        string[] Directorys = Directory.GetDirectories(absSavePath + @"/" + 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=/"common/" + Path.GetFileName(Files[i]) + "/" style=/"width:100px;height:100px;/" /><br/><input type=/"checkbox/" value=/"common/" + Path.GetFileName(Files[i]) + "/" name=/"picname/" onclick=/"getpicid();/" id=/"imgid" + i.ToString() + "/" /><label for=/"imgid" + i.ToString() + "/">" + 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> 

延伸 · 阅读

精彩推荐