2011-09-07 66 views

回答

0

您可以在頁面中動態地創建FileUpload控件。所以當用戶選擇,例如「上傳更多」鏈接時,將創建另一個FileUpload控件。

0
1.First put the Fileupload control in webform. 

`<asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" />` 

    2.Put the Button and Label like this. 

`<div> 
    <asp:FileUpload runat="server" ID="UploadImages" AllowMultiple="true" /> 
    <asp:Button runat="server" ID="uploadedFile" Text="Upload" OnClick="uploadFile_Click" /> 
    <asp:Label ID="listofuploadedfiles" runat="server" /> 
</div>` 

3.Write the code in button click. 

`protected void uploadFile_Click(object sender, EventArgs e) 
{ 
    if (UploadImages.HasFiles) 
    { 
     foreach (HttpPostedFile uploadedFile in UploadImages.PostedFiles) 
     { 
      uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"), 
      uploadedFile.FileName)); listofuploadedfiles.Text += String.Format("{0}<br />", uploadedFile.FileName); 
     } 
    } 
}`