免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
asp.net文件批量上傳

asp.net文件批量上傳  

2010-10-22 10:14:11|  分類: asp.net |  標簽: |字號 訂閱

html代碼

<script language="javascript" type="text/javascript">   
  function addFile()
  {
    //創(chuàng)建輸入元素(通用代碼)
    //添加上傳文件按鈕
    var fileUpLoadbutton = document.createElement("input");
    fileUpLoadbutton.setAttribute("type","file");
    fileUpLoadbutton.setAttribute("size","50");
    fileUpLoadbutton.setAttribute("name","File");
    fileUpLoadbutton.setAttribute("class","ButtonCss");
    //添加刪除按鈕
    var deleteImgbutton = document.createElement("img");
    deleteImgbutton.setAttribute("src","../images/pic22.gif");
    deleteImgbutton.setAttribute("style","width: 20px; height: 20px");
    //給
    deleteImgbutton.onclick=function(){deleteRow(1,this);};

   
    var lastIndex= document.getElementById('FileList').childNodes.length-1;
   
   
     if(lastIndex>-1)
     {
        var hideFile=document.getElementById('FileList').childNodes[lastIndex];
       
         if(hideFile.value=="")
         {
            return;
         }
       
        hideFile.style.display="none";
        var cell1 = document.createElement("td");
        var cell2 = document.createElement("td");  
       // var str = hideFile.value;
        var myList =new Array();
        myList=  hideFile.value.split("\\");
        cell1.innerHTML = myList[myList.length-1];// hideFile.value;      
        cell2.appendChild(deleteImgbutton);
        var row = document.createElement("tr");
        row.appendChild(cell1);
        row.appendChild(cell2);
        var tBody = document.createElement("tbody").appendChild(row);
        //識別當前瀏覽器
        if(navigator.appName.indexOf("Explorer") > -1)
        {
            document.getElementById("FileTable").childNodes[0].appendChild(tBody);
        }
        else
        {
            document.getElementById("FileTable").appendChild(tBody);
        }  
     }
    
     document.getElementById('FileList').appendChild(fileUpLoadbutton);
  }
 
   function deleteRow(targPos,btnObj)
    {
       var tabObj=document.getElementById("FileTable");
       
        var fileListLength = document.getElementById('FileList').childNodes.length;
       
        var tabRowsLength = tabObj.rows.length;
        
        for(var i =0;i<tabRowsLength;i++)
        {
            if(tabObj.getElementsByTagName('img')[i]==btnObj)
            {
                 //刪除當前選中行
                tabObj.deleteRow(i+targPos);
                //獲得選中行對應的上傳我文件對象
                var oldChild = document.getElementById('FileList').childNodes[i];
                //刪除上傳文件對象
                document.getElementById('FileList').removeChild(oldChild);
             
            }         
        }
  }
    </script>
    <div class="admin_title">
        上傳文件
    </div>
    <div>
         <table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <td align="left" valign="middle" class="style1">
                   <div id="FileList"><input id="File1" runat="server" name="File" size="50" type="file" /></div>
                </td>
                <td>
                   <input id="Button1" onclick="addFile()" size="26" style="height: 26px" type="button" value="增加文件" />
                </td>
            </tr>
        </table>
         <table style="width:100%"  id="FileTable">
        
            <tr>
                <td style="width:60%">文件名稱</td>
                <td style="width:40%">刪除文件</td>
            </tr>
        </table>
            <table border="0" cellpadding="0" cellspacing="0" height="26" width="100%">
            <tr>
                <td align="left" valign="middle">
                    <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="提交" />
                  
                   </td>
            </tr>
               
        </table>
    </div>

后臺CS代碼

    protected void Button1_Click(object sender, EventArgs e)
    {
        string strmessage = "";
        /**/
        /////附件
        HttpFileCollection fileList = HttpContext.Current.Request.Files;
        //保存附件
        for (int i = 0; i < fileList.Count; i++)
        {   /**////添加單個附件
            HttpPostedFile file = fileList[i];
            if (file.FileName.Length <= 0 || file.ContentLength <= 0)
            {
                break;
            }
            // 保存附件到硬盤中
            file.SaveAs(MapPath("../SaveFile/" + Path.GetFileName(file.FileName)));

       }
   }

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
javascript實現動態(tài)多附件上傳方法
開發(fā)跨瀏覽器的JavaScript
javascript 自制提示框
document.createElement()的用法
js DOM節(jié)點的創(chuàng)建、插入、刪除、查找、替換例子
Ajax動態(tài)更新頁面
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服