asp.net圖片上傳及刪除

來源:互聯網
上載者:User

標籤:style   blog   ar   color   os   sp   java   檔案   on   

方法一:UploadImage cetFU = new UploadImage();            if (cetFU.UpFile(FileUpload1, "teacher_picture"))//如果上傳成功 第一個參數表示fileupload外掛程式名稱,第二表示檔案夾的名稱            {                ImageName = cetFU.FileName;                ImageType = ImageName.Substring(ImageName.IndexOf("."), ImageName.Length - ImageName.IndexOf("."));            }            else//如果上傳失敗            {                Response.Write(bc.MessageBox(cetFU.ErrMsg));     //彈出錯誤提示            }能簡單的就進行上傳圖片。 方法二:protected void btnupload_Click(object sender, System.EventArgs e)        {                      string fullFileName = this.File1.PostedFile.FileName;            string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);擷取檔案名稱            string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);擷取檔案類型            string time = this.dropyear.Text + this.droplist.Text;            if (fileName.Length > 20)            {                Response.Write("<script language=‘javascript‘>alert(‘您上傳的檔案名稱必須在15個字元之內!‘);</script>");            }            else            {                if (type == "jpg" || type == "bmp" || type == "gif")                {                    conn.Open();                    string sql = "select * from kb where filepath=‘" + fileName + "‘";                    if (DB.ExecuteSqlEx(sql) == 1)//自己編寫的類的方法,執行SQL語句                    {                        this.File1.PostedFile.SaveAs(Server.MapPath("upload") + "\\" + fileName);                        sql = "insert into kb(filepath,kbtime) values(‘" + fileName + "‘,‘"+time+"‘)";                        DB.ExecuteSql(sql);                        this.Image1.ImageUrl = "upload/" + fileName;                        this.Image1.Visible = true;                        sql = "select count(*) from kb";                        SqlCommand cmd = new SqlCommand(sql, conn);                        this.lblNum.Text = cmd.ExecuteScalar().ToString();                        Response.Write("<script language=‘javascript‘>alert(‘上傳成功,您可以繼續上傳其它圖片!‘);</script>");                    }                    else                    {                        Response.Write("<script language=‘javascript‘>alert(‘圖片名已存在,請重新命名後再上傳!‘);</script>");                    }                }                else                {                    Response.Write("<script language=‘javascript‘>alert(‘你選擇的圖片格式錯誤!‘);</script>");                }            }        }相對比較清晰的說明了上傳的過程。 刪除檔案  File.Delete(Server.MapPath("teacher_picture\\" + ImageName));//刪除某個檔案 

 

asp.net圖片上傳及刪除

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.