【发布时间】:2011-09-07 07:18:27
【问题描述】:
我已经在我的应用程序中使用 asp:fileUpload 进行文件上传,但现在对于单个文件上传,我需要将其转换为多个文件上传
是否有任何代码可以添加到我现有的上传中以便我只追加?
【问题讨论】:
标签: asp.net c#-4.0 file-upload
我已经在我的应用程序中使用 asp:fileUpload 进行文件上传,但现在对于单个文件上传,我需要将其转换为多个文件上传
是否有任何代码可以添加到我现有的上传中以便我只追加?
【问题讨论】:
标签: asp.net c#-4.0 file-upload
您可以轻松地在页面中动态创建 FileUpload 控件。因此,当用户选择“上传更多”链接时,将创建另一个 FileUpload 控件。
【讨论】:
查看此链接:
http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-2
它展示了如何通过添加新的 FileUpload 控件来添加多个文件。 查看第 15 分钟的视频以查看最终结果。
在底部有完整的C#/VB源代码下载。
【讨论】:
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);
}
}
}`
【讨论】: