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;
                        }
                }
  • 相关阅读:
    详解 ES6 Modules
    es6常用基础合集
    透彻掌握Promise的使用,读这篇就够了
    Initialization of deep networks
    Logistic Regression and Gradient Descent
    一定要在年轻的时候读最难的书
    DEEP LEARNING WITH STRUCTURE
    我和NLP的故事(转载)
    Common Pitfalls In Machine Learning Projects
    C++中debug和release的区别 . 转载
  • 原文地址:https://www.cnblogs.com/whtydn/p/2060796.html
Copyright © 2011-2022 走看看