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

  • 相关阅读:
    Redis源码分析(二十一)--- anet网络通信的封装
    leetcode 总结part1
    leetcode String to Integer (atoi)
    leetcode 165. Compare Version Numbers
    leetcode 189. Rotate Array
    leetcode 168. Excel Sheet Column Title
    leetcode 155. Min Stack
    leetcode 228. Summary Ranges
    leetcode 204. Count Primes
    leetcode 6. ZigZag Conversion
  • 原文地址:https://www.cnblogs.com/Bright/p/2232023.html
Copyright © 2011-2022 走看看