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>
    

      

  • 相关阅读:
    LCA+链式前向星模板
    truffle编译合约常见问题及其在私链上的部署与交互
    RMQ入门解析
    最短路_搜索
    无向图边双联通分量+缩点
    有向图+强联通分量
    染色法判二分
    邻接表存图
    贪心算法
    贪心算法
  • 原文地址:https://www.cnblogs.com/VortexPiggy/p/2642616.html
Copyright © 2011-2022 走看看