我需要寫一個批量上傳的功能。我現在的做法是得到一個需要上傳文件的List...然后在用戶點擊上傳的時候,把List里面的文件遍歷的傳到服務器中去,我寫了如下的代碼,但我總認為會有些問題。因為剛用asp.net,沒什么經驗,請大家幫我看看。    protected void Button3_Click(object sender, EventArgs e)
    {
        maxno = 0;
        UpLoadInfo tmpInfo = (UpLoadInfo)Session["loadInfo"];  //這里面存的文件列表是客戶端的本地文件路徑
                                                                        //例如c:\\1.txt之類的        string dd = Server.MapPath("~/UploadFile/");                   foreach (infoEntry tmpEntry in tmpInfo.theList)
        {
            File.Copy(tmpEntry.m_fullfileName, dd + tmpEntry.m_fileName, true);  //我認為這一步執行會出問題,服務器看到客戶端的文件是c:\\1.txt,但卻不知道他的具體地址。雖然在本機上運行沒錯誤,但我覺得寫錯了,請大家指正
        }        tmpInfo.theList.Clear();
        Response.Redirect("UpLoad.aspx");    }

解决方案 »

  1.   


            i=2;
            function addFile()
            {    
    //                  debugger;                tb   =   document.getElementById( 'attAchments '); 
                    newRow   =   tb.insertRow(); 
                    newRow.insertCell().innerHTML = ' <input  type="file" name="FileUpload1" runat="server" onchange="CheckImgCss(this);" style="width: 260px"/> &nbsp; <input type=button value= "×"  style=" height:18px; width:18px" onclick= "delFile(this.parentElement.parentElement.rowIndex) "> ';                i++; 
             } 
            function   delFile(index) 
            { 
                    if(tb.rows.length   >0 )
                    {
                            document.getElementById( 'attAchments ').deleteRow(index); 
                    }
            } 
    HttpFileCollection HFC = HttpContext.Current.Request.Files;