/// <summary> /// 为服装城上传图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void submit1(object sender, EventArgs e) { //是否允许上传,默认为false bool isAllow = false; //上传文件保存路径 string mPath = Server.MapPath("~/image/"); //FileLoad控件不为空 if (this.FileUpload1.HasFile) { //文件类型 string fileType = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower(); //定义允许上传的文件的类型 string[] allowFile = { ".png", ".gif", ".jpeg", ".jpg" }; //检查文件的类型是否被允许 for (int i = 0; i < allowFile.Length; i++) { //如果允许 if (fileType == allowFile[i]) { //允许上传 isAllow = true; } } } //如果允许上传 if (isAllow == true) { try { //保存文件到服务器 FileUpload1.PostedFile.SaveAs(mPath + FileUpload1.FileName); //提示信息 Label4.Text = "上传成功!"; //图片显示 Image1.ImageUrl = "~/image/" + FileUpload1.FileName; Image1.Visible = true; //添加到数据库 BigImg mBigImg = new BigImg(); BigImgController mBigImgcontroller = new BigImgController(); mBigImg.AddTime = DateTime.Now.ToString(); mBigImg.ImgUrl = "~/image/" + FileUpload1.FileName; mBigImg.BigImgType = "服装城"; mBigImgcontroller.AddBigImg(mBigImg); } catch (HttpException ex) { Label4.Text = "上传失败!"; } } else { Label4.Text = "不可接受的文件类型!"; } }
//ThirdClassDm mThirdClassDm = new ThirdClassDm(); protected void Page_Load(object sender, EventArgs e) { //绑定服装城二级类目数据 this.dlClothes.DataSource = mSecondClassDm.GetSecondClothes(); this.dlClothes.DataBind(); //绑定商品图片信息 mClothGood.FirstClassDmID = "003"; this.dlistProductShow.DataSource = ImgInfo.GoodIDGetImgInfo(Good.FcIDGetGoodID(mClothGood)); this.dlistProductShow.DataBind(); //绑定商品宣传图片信息 //this.dlBigImg.DataSource = mClothImageInfo.GetBigImgAddress(); //this.dlBigImg.DataBind(); BigImg mBigImg = new BigImg(); string mCityType = "服装城"; BigImgController mBigImgController = new BigImgController(); this.BigImg.ImageUrl = mBigImgController.GetImgUrl(mBigImg, mCityType); }
protected void Page_Load(object sender, EventArgs e) { FirstClassDm LFirstName = new FirstClassDm(); LFirstName.FirstClassDmName = "家居家装"; List <SecondClassDm> lSecondClassName = new List <SecondClassDm>(); lSecondClassName = FirstClassDm.FcNameGetScName(LFirstName); dlistClassDm.DataSource = lSecondClassName; dlistClassDm.DataBind(); this.dlistProductShow.DataSource = ImgInfo.FurnitureCity(); this.dlistProductShow.DataBind(); //大图片 BigImg mBigImg = new BigImg(); string mCityType = "家具城"; BigImgController mBigImgController = new BigImgController(); this.BigImg.ImageUrl = mBigImgController.GetImgUrl(mBigImg, mCityType); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List <ImgInfo> adressList = new List <ImgInfo>(); adressList = ImgInfo.HomePageProductShow(); dlistProductShow.DataSource = adressList; dlistProductShow.DataBind(); //商城大图片 BigImg mBigImg = new BigImg(); BigImgController mBigImgController = new BigImgController(); string[] mUrl = mBigImgController.GetFirstBigImg(mBigImg); this.a1.HRef = mUrl[0]; this.a2.HRef = mUrl[1]; this.a3.HRef = mUrl[2]; this.a4.HRef = mUrl[3]; this.a5.HRef = mUrl[4]; //this.img6.Src = mUrl[0]; } }
//为首页添加多个图片 private void SaveFile() { //遍历表单元素 HttpFileCollection files = HttpContext.Current.Request.Files; //状态信息 string strOut = "<br>上传成功!上传的文件分别是:<hr color=red> <table Style='width:500px>'"; strOut += "<tr> <td>上传文件名</td></tr>"; try { for (int iFile = 0; iFile < files.Count - 3; iFile++) { //访问单独文件 HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension; fileName = System.IO.Path.GetFileName(postedFile.FileName); if (fileName != "") { //fileExtension = System.IO.Path.GetExtension(fileName); strOut += "<tr><td>" + fileName + "</td></tr></table>"; //保存文件到服务器 postedFile.SaveAs(Server.MapPath("~/image/") + fileName); BigImg mBigImg = new BigImg(); BigImgController mBigImgcontroller = new BigImgController(); mBigImg.AddTime = DateTime.Now.ToString(); mBigImg.ImgUrl = "~/image/" + fileName; mBigImg.BigImgType = "首页"; mBigImgcontroller.AddBigImg(mBigImg); } else { strOut = "<br> 请您选择一个文件!"; } } Label3.Text = strOut.ToString(); } catch (Exception Ex) { Label3.Text = Ex.Message.ToString(); } }