程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> asp.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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved