C#中有多个文件上传的代码片段吗?

发布于 2024-12-03 16:47:07 字数 120 浏览 0 评论 0原文

我已经在我的应用程序中使用 asp:fileUpload 进行文件上传,但是对于单个文件上传,现在我需要将其转换为多个文件上传

是否有任何代码可以在我现有的上传中添加,以便我只需附加?

I am already doing file upload in my application using asp:fileUpload but for single file upload now I need to convert that to multiple file upload

Is there any code to add in my existing uploading so that I just append?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

再可℃爱ぅ一点好了 2024-12-10 16:47:07

您可以轻松地在页面中动态创建 FileUpload 控件。因此,当用户选择“上传更多”链接时,将创建另一个 FileUpload 控件。

You can easily create FileUpload controls dynamically in your page. so when user select ,for example, "upload more" link, another FileUpload control will be created.

把梦留给海 2024-12-10 16:47:07

检查此链接:

http: //www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-2

它演示了如何通过添加新的 FileUpload 控件来添加多个文件。
查看第 15 分钟的视频即可查看最终结果。

底部有 C#/VB 的完整源代码下载。

Check this link:

http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-2

It shows how to add multiple files by adding new FileUpload controls.
Check video from minute 15 to see the final result.

At the bottom there is download of complete source code for C#/VB.

如梦 2024-12-10 16:47:07
   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);
       }
   }
}` 
   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);
       }
   }
}` 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文