小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

上傳按鈕單擊事件示例

 悟靜 2011-12-14

 protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        {
            try
            {
                MyConn = DB.CreateDB();

                string title =FunStr(this.TxtTitle.Text);//轉(zhuǎn)換
                string content =FunStr(this.TxtContent.Text);
                string ptype = Request.QueryString["action"].ToString();
                string FileName = myFile.Value;
                HttpPostedFile UpFile = myFile.PostedFile; //獲取對(duì)由客戶端指定的上傳文件的訪問(wèn)
                FileLength = UpFile.ContentLength;//獲取上傳文件的字節(jié)大小
                if (FileLength == 0)
                {
                    MyConn.Open();
                    OleDbCommand cmd1 = new OleDbCommand("insert into product(pro_name,title,content) values('" + ptype + "','" + title + "','" + content + "')",MyConn);
                    cmd1.ExecuteNonQuery();
                    Response.Write("<script>alert('數(shù)據(jù)添加成功');window.location.href='Admin_Add.aspx?action=" + ptype + "'</script>");
                    MyConn.Close();
                }
                else
                {
                    string exName = FileName.Substring(FileName.LastIndexOf(".") + 1).ToUpper();//截取圖片的后綴名,改名
                    if (exName == "JPG" || exName == "BMP" || exName == "GIF")//判斷圖片的類型
                    {
                        if (FileLength > 1024000)//判斷圖片是否大于200k(根據(jù)自己的需要判斷大小)
                        {
                            Response.Write("<script>alert('對(duì)不起,圖片大小不能大于1M');window.location.href='Admin_Add.aspx?action=" + ptype + "'</script>");
                            return;
                        }
                        else
                        {
                            string ImageName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + "." + exName;//圖片名稱設(shè)置為保存的時(shí)間
                            Byte[] FileByte = new Byte[FileLength]; //圖象文件儲(chǔ)存到數(shù)組 
                            Stream ObjectStream = UpFile.InputStream;//建立數(shù)據(jù)流對(duì)像,獲取一個(gè) Stream 對(duì)象,該對(duì)象指向一個(gè)上載文件,以準(zhǔn)備讀取該文件的內(nèi)容。

                            ObjectStream.Read(FileByte, 0, FileLength); //讀取圖象文件數(shù)據(jù)
                            string StrSql = "Insert Into product(pro_name,img,title,content) Values('" + ptype + "',@ImageName,'" + title + "','" + content + "')";
                            OleDbCommand Cmd = new OleDbCommand(StrSql, MyConn);
                            //Cmd.Parameters.Add("@Image",OleDbType.Binary, FileLength).Value = FileByte;
                            Cmd.Parameters.Add("@ImageName", OleDbType.VarChar, 100).Value = ImageName;
                            MyConn.Open();
                            this.myFile.PostedFile.SaveAs(Server.MapPath("/upload") + "\\" + ImageName);
                            Cmd.ExecuteNonQuery();
                            MyConn.Close();
                            Response.Write("<script>alert('數(shù)據(jù)添加成功');window.location.href='Admin_Add.aspx?action="+ptype+"'</script>");
                        }
                    }
                    else
                    {
                        Response.Write("<script>alert('對(duì)不起,請(qǐng)選擇正確的的圖片!');window.location.href='Admin_Add.aspx?action=" + ptype + "'</script>");
                        return;
                    }
                }
               

            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "')</script>");
            }
        }

    }

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多