zoukankan      html  css  js  c++  java
  • Asp.Net图片上传

    <div>

                            <asp:FileUpload ID="FileUpload1" runat="server" Height="25px"/>
                            <asp:ImageButton runat="server" ID="btn_Upload" ImageUrl="~/Activity/images/upload.gif"
                                Style="margin-bottom: -8px;" OnClick="btn_Upload_Click" /><br />
                            <asp:Image ID="imgUrl" runat="server" Visible="false" /></div> 

    protected void btn_Upload_Click(object sender, ImageClickEventArgs e)
            {
                string path = "/uploadfiles/Activity/";
                string folderPathforsave = Server.MapPath(path);
                if (!Directory.Exists(folderPathforsave))
                {
                    Directory.CreateDirectory(folderPathforsave);
                }

                string filename = FileUpload1.FileName;

                if (filename != "")
                {
                    filename = filename.Substring(filename.LastIndexOf("."));
                    if (filename.ToLower() == ".jpg" || filename.ToLower() == ".bmp" || filename.ToLower() == ".gif")
                    {
                        string strpic = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now)+filename;
                        fup_Act_Image.SaveAs(folderPathforsave + strpic);
                        path += strpic;
                        imgUrl.Visible = true;
                        imgUrl.ImageUrl = path;
                    }
                    else
                    {
                        MsgBox.MsgBoxShow(this.Page, "支持jpg,bmp,gif等上传文件格式!");
                        return;
                    }
                }
            }

  • 相关阅读:
    前端日常开发常用功能系列之乱序
    ES6系列之箭头函数
    ES6系列之let/const及块级作用域
    前端日常开发常用功能系列之数组扁平
    前端日常开发常用功能系列之数组最值
    前端日常开发常用功能系列之拷贝
    前端日常开发常用功能系列之数组去重
    前端日常开发常用功能系列之节流
    前端日常开发常用功能系列之防抖
    数据库连接池优化配置(druid,dbcp,c3p0)
  • 原文地址:https://www.cnblogs.com/Bright/p/2232023.html
Copyright © 2011-2022 走看看