代码
 1     <script language="javascript" type="text/javascript">
 2         function addfile()
 3         {
 4            //var filehtml="<div></div>";         
 5            var filediv=document.createElement("div");
 6                filediv.innerHTML="<input type='file' name='ff'>&nbsp;&nbsp;<a href=\"javascript:;\" onclick=\"deletefile(this)\">delete</a>";             
 7            var files=document.getElementById("files");
 8                files.appendChild(filediv);
 9         }
10         function deletefile(obj)
11         {
12            var dele=obj.parentNode;
13           document.getElementById("files").removeChild(dele);
14         }
15     </script>
16 </head>
17 <body>
18     <form id="form1" enctype="multipart/form-data"  runat="server" method="post" >
19     <div>
20         <input type="button" value="浏览"  onclick="addfile()"/>
21        <div id="files">
22         <input type="file"  name="ff"/>        
23        </div>
24         <asp:Button runat="server" ID="btSend"  Text="upload" onclick="btSend_Click"/><asp:Label runat="server" ID="lbStatus"></asp:Label>
25     </div>
26     </form>

 

代码
 1    lbStatus.Text = string.Empty;
 2         HttpFileCollection httpcollection = Request.Files;
 3         int j = 0;
 4         int count = httpcollection.Count;
 5         for (int i = 0; i < httpcollection.Count; i++
 6         {
 7             try
 8             {
 9                 
10                 HttpPostedFile fs = httpcollection[i];
11                 if (!string.IsNullOrEmpty(fs.FileName))
12                 {
13                     j++;
14                     string Extesions = System.IO.Path.GetExtension(fs.FileName);//扩展名
15                     string filenames = System.IO.Path.GetFileName(fs.FileName);
16                     fs.SaveAs(Server.MapPath("image/"+ Guid.NewGuid().ToString()+Extesions);
17                 }
18             }
19             catch { continue; }         
20         }
21         lbStatus.Text = "本次上传共" + count + "张图片,<font color=blue>" + j + "</font>张成功<font color=red>" + (count - j) + "</font>张失败";

 

posted on 2010-01-12 10:46  〤‵坠落者...  阅读(154)  评论(0编辑  收藏  举报