zoukankan      html  css  js  c++  java
  • 【Asp.Net从零开始】:上传文件(FileUpload)

    public partial class FileUpload : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void btn_Save_onclick(object sender, EventArgs e)
        {
            Boolean fileOK = false;
            String path = Server.MapPath("~/Uploads/");
            if (fu.HasFile)
            {
                String fileExtension =
                    System.IO.Path.GetExtension(fu.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }
    
            if (fileOK)
            {
                try
                {
                    fu.PostedFile.SaveAs(path + fu.FileName);
                }
                catch (Exception ex)
                {
                   
                }
            }
            else
            {
               
            }
            
        }
    }
    

      

    <body>
        <form id="form1" runat="server">
        <div>
        <asp:FileUpload ID="fu" runat="Server" MaxRequestLength="" BackColor="#6699FF" Height="42px" Width="257px" />
            <br />
            <asp:Button Text="存储" ID="btn_Save" runat="server" OnClick="btn_Save_onclick" 
                style="margin-left: 153px" />
        </div>
        </form>
    </body>
    

      

  • 相关阅读:
    [Postman]历史(8)
    [Postman]响应(7)
    [Postman]请求(6)
    [Postman]查找替换(5)
    ORA-02050故障诊断一例
    转 js实践篇:例外处理Try{}catch(e){}
    转 PHP
    HTML DOM getElementById() 方法
    地点选择
    9i 和 11 g 区别
  • 原文地址:https://www.cnblogs.com/VortexPiggy/p/2642616.html
Copyright © 2011-2022 走看看