//保存头像 private void buttonSaveFace_Click(object sender, EventArgs e) { string responseText; UploadPic httpRequestClient = new UploadPic(); httpRequestClient.SetFieldValue("username", AppInfo.PERSONAL_INFO.Username);//加数据 byte[] imageBytes; using (MemoryStream ms = new MemoryStream()) { currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Position = 0; imageBytes = new byte[ms.Length]; ms.Read(imageBytes, 0, imageBytes.Length); } httpRequestClient.SetFieldValue("face", "***", "application/octet-stream", imageBytes); httpRequestClient.Upload(AppConst.WebUrl + "baseInfo", out responseText); Debug.Print("上传结果是" + responseText); if (responseText == "true") { //修改新头像 AppInfo.SELF_FACE = this.currentImage; saveOKSafePost(); //修改本地缓存的头像 //本地缓存 this.currentImage.Save(AppConst.WinPicPath + "friend" + AppInfo.PERSONAL_INFO.Username + ".jpg"); } else { MessageBox.Show("更改失败!"); } }
//保存头像 private void buttonSaveFace_Click(object sender, EventArgs e) { string responseText; UploadPic httpRequestClient = new UploadPic(); httpRequestClient.SetFieldValue("gid", m_gid.ToString());//加数据 byte[] imageBytes; using (MemoryStream ms = new MemoryStream()) { currentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); ms.Position = 0; imageBytes = new byte[ms.Length]; ms.Read(imageBytes, 0, imageBytes.Length); } httpRequestClient.SetFieldValue("face", "***", "application/octet-stream", imageBytes); httpRequestClient.Upload(AppConst.WebUrl + "groupBaseInfo", out responseText); Debug.Print("上传结果是" + responseText); if (responseText == "true") { //修改新头像 m_FormShowGroupInfo.refreshFaceSafePost(currentImage); ////修改本地缓存的头像 //this.currentImage.Save(AppConst.WinPicPath + "group"+ m_gid + ".jpg"); //FaceMgr.Instance.modifyFace(m_gid); saveOKSafePost(); } else { MessageBox.Show("更改失败!"); } }
protected void save_Click(object sender, EventArgs e) { save.Enabled = false; update.Enabled = true; string userId = Session["userId"].ToString(); string Name = txtName.Text; string Sex = ""; if (Female.Checked) { Sex = Female.Text; } else { Sex = Male.Text; } string Year = year.SelectedValue; string Month = month.SelectedValue; string Day = day.SelectedValue; string Type = TeachType.SelectedValue; string Major = TeachMajor.SelectedValue; string City = txtCity.Text; string Unit = txtUnit.Text; string Intro = txtIntro.Text; string Phone = txtPhone.Text; string filepath = "~/upload/image/"; //文件路径 string serverPath = Server.MapPath(filepath); //判断服务器目录是否存在 if (System.IO.Directory.Exists(serverPath) == false)//如果不存在就创建文件夹 { System.IO.Directory.CreateDirectory(serverPath); } UploadPic.SaveAs(serverPath + Path.GetFileName(UploadPic.FileName)); string picName = Path.GetFileName(UploadPic.FileName); string picLink = filepath + Path.GetFileName(UploadPic.FileName); string[] sqlT = new string[2]; int i = 0; sqlT[i++] = "update TeacherInfo set TeachName='" + Name + "', TeachSex='" + Sex + "',BirthYear='" + Year + "', BirthMonth='" + Month + "',BirthDay='" + Day + "',TeachTypeId='" + Type + "',TeachCity='" + City + "',TeachUnit='" + Unit + "', TeachPhone='" + Phone + "',TeachMajor='" + Major + "',intro='" + Intro + "',TeachPic='" + picLink + "'where TeachId='" + userId + "'"; sqlT[i] = "update CourseInfo set teacher='" + Name + "'where teacher='" + Session["userName"].ToString() + "'"; if (DataOperate.ExecTransaction(sqlT)) { ClientScript.RegisterStartupScript(this.GetType(), "", " <script>alert('成功完善个人信息')</script>"); } else { ClientScript.RegisterStartupScript(this.GetType(), "", " <script>alert('个人信息完善失败,请重试')</script>"); //提示注册失败 } init_Info(); User_Info(); }
protected void save_Click(object sender, EventArgs e) { string userId = Session["userId"].ToString(); string Name = txtName.Text; string Sex = ""; if (Female.Checked) { Sex = Female.Text; } else { Sex = Male.Text; } string Year = year.SelectedValue; string Month = month.SelectedValue; string Day = day.SelectedValue; string TypeName = UserType.SelectedValue; string type_sql = "select * from StudentInfo inner join StudentTypeInfo on StudentInfo.StuTypeId = StudentTypeInfo.TypeId"; SqlDataReader sdr = DataOperate.GetRow(type_sql); sdr.Read(); string TypeId = sdr["StuTypeId"].ToString(); string Major = MajorCourse.SelectedValue; string City = txtCity.Text; string Unit = txtUnit.Text; string Phone = txtPhone.Text; string filepath = "~/upload/image/"; //文件路径 string serverPath = Server.MapPath(filepath); //判断服务器目录是否存在 if (System.IO.Directory.Exists(serverPath) == false)//如果不存在就创建文件夹 { System.IO.Directory.CreateDirectory(serverPath); } UploadPic.SaveAs(serverPath + Path.GetFileName(UploadPic.FileName)); string picName = Path.GetFileName(UploadPic.FileName); string picLink = filepath + Path.GetFileName(UploadPic.FileName); string sql = "update StudentInfo set StuName='" + Name + "', StuSex='" + Sex + "',BirthYear='" + Year + "', BirthMonth='" + Month + "',BirthDay='" + Day + "',StuTypeId='" + TypeId + "',StuCity='" + City + "',StuSchool='" + Unit + "',StuMajor='" + Major + "', StuPhone='" + Phone + "',StuPic='" + picLink + "' where StuId='" + userId + "'"; if (DataOperate.ExecSQL(sql)) { ClientScript.RegisterStartupScript(this.GetType(), "", " <script>alert('成功完善个人信息')</script>"); } else { ClientScript.RegisterStartupScript(this.GetType(), "", " <script>alert('个人信息完善失败,请重试')</script>"); //提示注册失败 } }
public ActionResult UploadFile(HttpPostedFileBase file) { try { HttpPostedFileBase imgFile = Request.Files["imgFile"]; string oldLogo = "/Upload/"; string img = UploadPic.MvcUpload(file, new string[] { ".png", ".gif", ".jpg" }, 1, System.Web.HttpContext.Current.Server.MapPath(oldLogo)); img = ".." + oldLogo + img; return(Json(new { data = new { src = img }, code = 0, msg = "成功" }, JsonRequestBehavior.DenyGet)); } catch (Exception ex) { return(Json(new { data = new { src = "" }, code = 500, msg = "上传失败" }, JsonRequestBehavior.DenyGet)); } }
public IActionResult Upload() //Make a empty new model so user can post new model. { var model = new UploadPic(); return(View(model)); }