学习, And 整理了一下.

(一). 示例图片

      Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)

(二). 示例代码

 

  1Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)public partial class UpMultiFileControl2 : System.Web.UI.UserControl
  2Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
  3Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    protected void Page_Load(object sender, EventArgs e)
  4Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
  5Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        if (!Page.IsPostBack)
  6Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
  7Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            SaveCurrentPageFileControls();
  8Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        }

  9Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }

 10Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    protected void btAddFile_Click(object sender, EventArgs e)
 11Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 12Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        AddOneFileControl();
 13Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }

 14Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
 15Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /**//// <summary>
 16Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// 添加一个上传文件控件
 17Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// </summary>

 18Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    private void AddOneFileControl()
 19Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 20Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        ArrayList al = new ArrayList();
 21Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        this.tbFiles.Rows.Clear();
 22Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        GetFileControlsFromSession();        
 23Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        HtmlTableRow htr = new HtmlTableRow();
 24Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        HtmlTableCell htc = new HtmlTableCell();        
 25Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        htc.Controls.Add(new FileUpload());
 26Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        htr.Controls.Add(htc);
 27Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        this.tbFiles.Rows.Add(htr);
 28Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        SaveCurrentPageFileControls();
 29Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }

 30Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
 31Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /**//// <summary>
 32Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// 读取缓存中存储的上传文件控件集
 33Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// </summary>

 34Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    private void GetFileControlsFromSession()
 35Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 36Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        ArrayList al = new ArrayList();       
 37Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        if (Session["FilesControls"!= null)
 38Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 39Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            al = (System.Collections.ArrayList)Session["FilesControls"];
 40Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            for (int i = 0; i < al.Count; i++)
 41Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 42Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                HtmlTableRow htr1 = new HtmlTableRow();                
 43Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                HtmlTableCell htc1 = new HtmlTableCell();
 44Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                htc1.Controls.Add((System.Web.UI.WebControls.FileUpload)al[i]);
 45Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                htr1.Controls.Add(htc1);
 46Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                this.tbFiles.Rows.Add(htr1);
 47Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            }

 48Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        }

 49Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }

 50Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    
 51Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /**//// <summary>
 52Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// 保存当前页面上传文件控件集到缓存中
 53Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// </summary>    

 54Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    private void SaveCurrentPageFileControls()
 55Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){        
 56Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        ArrayList al = new ArrayList();        
 57Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        foreach (Control controlTR in this.tbFiles.Controls)
 58Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 59Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            if (controlTR.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlTableRow")
 60Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 61Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                HtmlTableCell htc = (HtmlTableCell)controlTR.Controls[0];
 62Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                foreach (Control controlFileUpload in htc.Controls)
 63Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 64Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                    if (controlFileUpload.GetType().ToString() == "System.Web.UI.WebControls.FileUpload")
 65Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 66Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                        FileUpload tempFileUpload = (FileUpload)controlFileUpload;
 67Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                        al.Add(tempFileUpload);
 68Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                    }

 69Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                }

 70Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)            }
            
 71Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        }
  
 72Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        Session.Add("FilesControls", al);
 73Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }

 74Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
 75Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    protected void btUpFiles_Click(object sender, EventArgs e)
 76Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 77Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        UpLoadFiles();
 78Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }

 79Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
 80Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /**//// <summary>
 81Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// 上传文件操作
 82Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    /// </summary>

 83Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    private void UpLoadFiles()
 84Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
 85Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        string filepath = Server.MapPath("./")+"UploadFiles";
 86Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        
 87Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        HttpFileCollection uploadedFiles = Request.Files;       
 88Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        for (int i = 0; i < uploadedFiles.Count; i++)
 89Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)        Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){    
 90Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           HttpPostedFile userPostedFile = uploadedFiles[i];        
 91Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           try
 92Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){    
 93Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)              if (userPostedFile.ContentLength > 0 )
 94Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)              Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){  
 95Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                 userPostedFile.SaveAs(filepath + "\\" + System.IO.Path.GetFileName(userPostedFile.FileName));
 96Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)                 Response.Write("已上传文件: \"" + filepath +"\\"+ userPostedFile.FileName +"\"<br><br>" );                                   
 97Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)              }
    
 98Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           }
 
 99Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           catch
100Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
101Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)               Response.Write("上传文件: \"" + userPostedFile.FileName +"\"出错!");
102Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           }
    
103Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)       }

104Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)       if (Session["FilesControls"!= null)
105Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)       Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载){
106Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)           Session.Remove("FilesControls");
107Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)       }

108Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)    }
    
109Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)}

 

(三). 改变上传文件大小和时间限制

       <httpRuntime>
            executionTimeout="110"              //允许上传文件最大等待时间
            maxRequestLength="4096"        //上传文件大小,默认为4M
       </httpRuntime>

       上传文件大小是由上面两个参数所决定的.  涉及到安全因素,最好不要设得太大.      

(四). 示例源代码下载

       https://files.cnblogs.com/ChengKing/UpMultiFileControl.rar

(五).控件缺点

       由于安全原因, 用服务端控件实现,回发时选择的文件不能够保存.



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=699244

相关文章:

  • 2021-11-10
  • 2021-08-15
  • 2022-01-15
  • 2021-05-21
  • 2021-11-25
  • 2021-09-29
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2022-03-09
  • 2021-10-02
  • 2022-12-23
相关资源
相似解决方案