zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

Net实例文件ASP代码 删除 读取 磁盘
2023-06-13 09:15:06 时间

复制代码代码如下:


   protectedvoidReadFile()    //读取文件夹,文件
   {
       stringsavePath=@"common";
       StringBuilderoutstring=newStringBuilder();
       stringabsSavePath=Server.MapPath(savePath);
       string[]Directorys=Directory.GetDirectories(absSavePath+@"/"+Page.User.Identity.Name);
       //for(inti=0;i<Directorys.Length;i++)
       //{
       //   Response.Write(Directorys[i]+"<br/>");
       //}
       //Response.Write("Directoryscount:"+Directorys.Length+"个 <br/>---------<br>");
       string[]Files=Directory.GetFiles(absSavePath+@""+Page.User.Identity.Name,"*");
       outstring.Append("<ul>");
       for(inti=0;i<Files.Length;i++)
       {
           if(Path.GetFileName(Files[i])!="Thumbs.db")
           {
               outstring.Append("<li><imgsrc=/"common/"+Path.GetFileName(Files[i])+"/"style=/"width:100px;height:100px;/"/><br/><inputtype=/"checkbox/"value=/"common/"+Path.GetFileName(Files[i])+"/"name=/"picname/"onclick=/"getpicid();/"id=/"imgid"+i.ToString()+"/"/><labelfor=/"imgid"+i.ToString()+"/">"+Path.GetFileName(Files[i])+"</label></li>");
           }
       }
       outstring.Append("</ul>");
       Response.Write(outstring.ToString());
   }

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


复制代码代码如下:

//循环遍历复选框
<scriptlanguage="javascript"type="text/javascript"defer="defer">
   varimgnum=document.getElementsByTagName("input");
   varimgids="";
   functiongetpicid()
   {
       document.getElementById("hidimgid").value="";
       for(vari=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>