• 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());
                }
            }

        }

  • 相关阅读:
    oa_mvc_easyui_删除(6)
    oa_mvc_easyui_详细页(5)
    oa_mvc_easyui_分页(4)
    oa_mvc_easyui_后台布局(3)
    oa_mvc_easyui_登录完成(2)
    oa_mvc_easyui_项目搭建及登录页面验证码(1)
    第六篇 ajax
    AOP切入点表达式
    开发的时候,有异步回调的时候,问题终于解决了
    mysql数据表结构查询
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/2791578.html
Copyright © 2020-2023  润新知