private void button1_Click(object sender, EventArgs e) { #region 图片并生成新html Regex r = new Regex("<IMG[\\s\\S]*?>"); MatchCollection mc = r.Matches(htmlEditor1.BodyInnerHTML); ///string[] mc = CommonClass.HtmlUtility.GetElementsByTagName(htmlEditor1.BodyInnerHTML, "IMG"); String html = htmlEditor1.BodyInnerHTML; Uri endpoint = new Uri(Securit.DeDES(IniReadAndWrite.IniReadValue("fileManage", "filePath"))); for (int i = 0; i < mc.Count; i++) { if (mc[i].Value.Contains("src=\"http://")) { continue; } using (WebClient myWebClient = new WebClient()) { myWebClient.UploadFileCompleted += new UploadFileCompletedEventHandler(uploadCompleted); String imgHtml = mc[i].Value; string inPath = HtmlUtility.GetTitleContent(imgHtml, "img", "src"); //imgHtml.Substring(startIndex, imgHtml.LastIndexOf("\"") - startIndex); try { String newName = user.Id + "_" + DateTime.Now.Ticks + inPath.Substring(inPath.LastIndexOf(".")); String tempPath = Application.StartupPath.ToString() + "\\temp\\" + newName; File.Copy(inPath, tempPath, true); myWebClient.UploadFileAsync(endpoint, tempPath); String newString2 = imgHtml.Remove(imgHtml.IndexOf("src"), inPath.Length + 6);//.Remove(imgHtml.LastIndexOf('>'))+" src=\"" + Securit.DeDES(IniReadAndWrite.IniReadValue("fileManage", "savePath")) + newName + "\">"; string newString1 = newString2.Remove(newString2.LastIndexOf('>')); string newString = newString1 + " src=\"" + Securit.DeDES(IniReadAndWrite.IniReadValue("fileManage", "savePath")) + @"LogPic\" + newName + "\">"; //html html = html.Replace(mc[i].Value, newString); } catch (Exception exp) { MessageBox.Show(exp.ToString()); return; } } } #endregion StaffLog staffLog = null; if (htmlEditor1.Tag == null) { staffLog = new StaffLog(); } else if (htmlEditor1.Tag != null) { staffLog = (StaffLog)htmlEditor1.Tag; } staffLog.Content = html; staffLog.State = (int)IEntity.stateEnum.Normal; staffLog.WriteTime = DateTime.Now.Ticks; staffLog.TimeStamp = DateTime.Now.Ticks; staffLog.Staff = user; staffLog.SharedStaffs = sharedUser; try { if (staffLog.Id == 0) { object be = baseService.saveEntity(staffLog); staffLog.Id = int.Parse(be.ToString()); } else if (staffLog.Id != 0) { baseService.SaveOrUpdateEntity(staffLog); } #region 向服务中发送数据 try { KjqbService.Service1Client ser = new KjqbService.Service1Client(); if (sharedUser != null && sharedUser.Count > 0) { foreach (WkTUser u in sharedUser) { KjqbService.LogInService ll = new KjqbService.LogInService(); ll.LogId = staffLog.Id; ll.WriteUserId = this.user.Id; ll.ShareUserId = u.Id; ll.TimeStamp = DateTime.Now.Ticks; ser.SaveInLogListInService(ll); } } } catch { } #endregion } catch { MessageBox.Show("保存失败!"); return; } MessageBox.Show("保存成功!"); this.DialogResult = DialogResult.OK; this.Close(); }