protected void lbtnUp_Click(object sender, EventArgs e) { if (fuProductPhoto.HasFile) { if (fuProductPhoto.PostedFile.ContentLength > 100 * 1024) { Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("照片大小不能超过100K,请重新选择")); } else { if (fuProductPhoto.PostedFile.ContentType == "image/gif" || fuProductPhoto.PostedFile.ContentType == "image/x-png" || fuProductPhoto.PostedFile.ContentType == "image/pjpeg" || fuProductPhoto.PostedFile.ContentType == "image/bmp") { string strNewName = WebUnitily.GetName() + System.IO.Path.GetExtension(fuProductPhoto.FileName); string strPath = Server.MapPath("~/photo/" + strNewName); fuProductPhoto.PostedFile.SaveAs(strPath); imgPhoto.ImageUrl = "~/photo/" + strNewName; ViewState["photo"] = strNewName; } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("请上传常用格式的图片")); } } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", WebUnitily.AlertUrl("请您选择照片后再上传?")); } }