圖片文件上傳代碼

private void Button1_Click(object sender, System.EventArgs e)
  {
   string fullfilename=this.File1.PostedFile.FileName;//上傳的文件名
                                                       string size=this.file1.postedFile.ContentLength.ToString();//獲取文件的大小
                                                   
   string filename=fullfilename.Substring(fullfilename.LastIndexOf("//")//獲得文件的+1);
   string type=fullfilename.Substring(fullfilename.LastIndexOf(".")+1);//得到文件的後綴名
   
   if (type=="jpg"||type=="bmp"||type=="gif"||type=="ico")
   {
    this.File1.PostedFile.SaveAs(Server.MapPath("upload")+"//"+filename);
    this.Imp.Visible=true;
    this.Imp.ImageUrl="upload/"+filename;
 
   }
   else
   {
    Response.Write("<script language='javascript'>alert('你上傳的圖片格式有錯誤!')</script>");
   
   
   }
  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章