zoukankan      html  css  js  c++  java
  • fileupload控件

     ASP网页中的代码:

     <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:FileUpload ID="FileUpload4" runat="server" /><br />
            <asp:Button ID="Button1" runat="server" Text="上传" onclick="Button1_Click" />
            <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

        </div>
       
        </form>

    方法中代码:

     protected void Button1_Click(object sender, EventArgs e)
        {
            string filepath = Server.MapPath("~/upload");
            HttpFileCollection uploadFile = Request.Files;
            Label1.Text = "";
            for (int i = 0; i < uploadFile.Count; i++)
            {
                try
                {
                    HttpPostedFile userpostfile = uploadFile[i];
                    if (userpostfile.ContentLength > 0)
                    {
                    
                        Label1.Text += "<u>文件#" + (i + 1) + "</u><br/>";
                        Label1.Text += "文件内容类型" + userpostfile.ContentType + "<br/>";
                        Label1.Text += "文件大小" + userpostfile.ContentLength + "<br/>";
                        Label1.Text += "文件名" + userpostfile.FileName + "<br/>";

                        userpostfile.SaveAs(filepath + "\\" + Path.GetFileName(userpostfile.FileName));
                //userpostfile.FileName 如果这种方法不行,并不是代码的问题,而是浏览器的问题,改一下兼容模式就好了,因为有的浏览器
                        //提交的方式不同,有的只是提交filename,而有的却是把整个路径全部提交上去,所以会报错.
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.ToString());
                }
            }

        }

  • 相关阅读:
    命令行颜色换算器(基于python)
    VPS常用操作(自用)
    自动读取虚拟币ETC行情并语音提醒的小工具(mac OSX)
    nginx最基本操作
    一个平庸程序员的自白
    unity 2d游戏 按y坐标排序子对象
    开源输入法推荐
    unity插件,从一段文字中提取中文并去重
    考试总结(CE???)
    螺旋矩阵
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/2791578.html
Copyright © 2011-2022 走看看