zoukankan      html  css  js  c++  java
  • 轻松实现一个页面多文件上传

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace FileIO
    {
        
    public partial class uploadFile : System.Web.UI.Page
        {
            
    protected void Page_Load(object sender, EventArgs e)
            {

            }

            
    protected void Button1_Click(object sender, EventArgs e)
            {
                
    string path = Server.MapPath("~/upload/");
                HttpFileCollection uploadFiles 
    = Request.Files;
                
    for (int i = 0; i < uploadFiles.Count; i++)
                {
                    HttpPostedFile userPostedFile
    =uploadFiles[i];
                    
    try
                    {
                        
    if (userPostedFile.ContentLength > 0)
                        {
                            userPostedFile.SaveAs(path 
    + userPostedFile.FileName);
                        }
                    }
                    
    catch (Exception)
                    {
                        
                        
    throw;
                    }
                }
               
            }
        }
    }
    Code
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="uploadFile.aspx.cs" Inherits="FileIO.uploadFile" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title></title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
        
            
    <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="upload" />
        
        
    </div>
        
    </form>
    </body>
    </html>
  • 相关阅读:
    YearsBetween、MonthsBetween ... YearSpan、MonthSpan ... 间隔时间
    SysUtilsFunction
    DateOf、TimeOf、YearOf、MonthOf、WeekOf、DayOf、HourOf、MinuteOf、SecondOf、MilliSecondOf 提取时间成分
    MathFunction
    DateUtilsFunction
    关于发表评论时的“无法验证数据”的错误
    用ISAPI_Rewrite实现反向代理(ReverseProxy)
    [公告]取消了后台管理中的统计功能
    推荐一个不错的SharePoint文档库树形显示WebPart及谈谈写Blog的好处
    [公告]镜像站点可以登录并发表文章
  • 原文地址:https://www.cnblogs.com/shineqiujuan/p/1528196.html
Copyright © 2011-2022 走看看