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;
                    }
                }
            }

  • 相关阅读:
    000_linux之Ubuntu安装
    001_linux基础命令
    018_linux驱动之_阻塞和非阻塞
    019_linux驱动之_定时器的引入
    017_linux驱动之_信号量
    016_linux驱动之_原子操作
    python logging模块整理
    python sys与shutil模块
    python configparser模块
    python os模块
  • 原文地址:https://www.cnblogs.com/Bright/p/2232023.html
Copyright © 2011-2022 走看看