zoukankan      html  css  js  c++  java
  • ASP.NET上传多个文件

    HttpFileCollection与HttpPostedFile这二个类的组合就可以完成

    前端

    <asp:FileUpload ID="FileUpload1" runat="server" />
            
    <br />
            
    <asp:FileUpload ID="FileUpload2" runat="server" />
            
    <br />
            
    <asp:FileUpload ID="FileUpload3" runat="server" />
            
    <br />
            
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
            
    <br />
            
    <asp:Label ID="Label1" runat="server"></asp:Label>

    后端

    string filePath = Server.MapPath(""+ "\\UploadFiles\\";

                HttpFileCollection uploadFiles 
    = Request.Files;
                
    for (int i = 0; i < uploadFiles.Count; i++)
                {
                    HttpPostedFile userPostFile 
    = uploadFiles[i];
                        
    try
                        {
                            
    if (userPostFile.ContentLength > 0)
                            {
                                userPostFile.SaveAs(filePath 
    + Path.GetFileName(userPostFile.FileName));
                                Label1.Text 
    = "上传成功!";
                            }
                        }
                        
    catch (Exception ex)
                        {
                            Label1.Text 
    = "Error: " + ex.Message;
                        }
                }
  • 相关阅读:
    財智V6.0(完美破解序列号特别版)
    垂死挣扎还是涅槃重生 -- Delphi XE5 公布会归来感想
    HDU1006
    HDU 1385 Minimum Transport Cost 最短路径题解
    fast-json.jar的用法
    curl命令具体解释
    mysql很全的和完整的总结
    MongoDB入门简单介绍
    Tuxedo入门学习
    BP神经网络基本原理
  • 原文地址:https://www.cnblogs.com/whtydn/p/2060796.html
Copyright © 2011-2022 走看看