//发布文章 protected void btnPublish_Click(object sender, EventArgs e) { string artTitle = txtArtTitle.Text; //文章标题 int artType = int.Parse(ddlArtType.SelectedValue); //文章类别 DateTime artPubTime = DateTime.Now; //文章发布时间 //string artContent = CKEditorControl1.Text; //文章内容 string artContent = Request.Params["content"]; //文章内容 int maxOrder = 0; string sqlQuery = string.Format("select max(ArtOrder) from T_ARTICLE where ArtType={0}", artType); DataTable dtQuery = SqlServerHooker.GetDataTable(sqlQuery); if (dtQuery == null || dtQuery.Rows[0][0].ToString() == "") { maxOrder = 1; } else { maxOrder = (int)dtQuery.Rows[0][0] + 1; } bool isSuc = true; if (radioList.SelectedIndex == 0) //新增文章 { string sqlInsert = string.Format("insert into T_ARTICLE(ID,ArtType,ArtTitle,ArtDate,ArtContent,ArtOrder) values('{0}',{1},'{2}','{3}','{4}',{5})", Guid.NewGuid(), artType, artTitle, artPubTime.ToString("yyyy-MM-dd HH:mm:ss"), artContent, maxOrder); isSuc = SqlServerHooker.InsertDataToTable(sqlInsert); } else //更新文章 { string sqlUpdate = string.Format("update T_ARTICLE set ArtType={0},ArtTitle='{1}',ArtContent='{2}' where ID='{3}'", artType, artTitle, artContent, _selectArtID); isSuc = SqlServerHooker.InsertDataToTable(sqlUpdate); } //生成静态html网页 string url = string.Format("http://127.0.0.1:8080/article/detail?type={0}&order={1}", artType, maxOrder); string id = OtherTool.GuidTo16String(); string path = Server.MapPath(string.Format("~/article/{0}.html", id)); CreateStaticHtml.ReturnStaticHtml(url, path); //上传html文件 bool isUpdateSuc = _ftpManager.UploadFile(path, "article/"); File.Delete(path); //上传图片 string ftpPath = "ueditor/net/upload/image/"; string imageDir = Server.MapPath("~/artpublish/ueditor/net/upload/image/"); string[] filePaths = Directory.GetFiles(imageDir); string imageNames = string.Empty; foreach (string filePath in filePaths) { //压缩图片 string newFilePath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath) + "new" + Path.GetExtension(filePath); ResizeImage.GetPicThumbnail(filePath, newFilePath, 222, 650, 100); FileInfo fileInfo = new FileInfo(newFilePath); fileInfo.MoveTo(filePath); imageNames += Path.GetFileName(filePath) + ";"; _ftpManager.UploadFile(filePath, ftpPath); File.Delete(filePath); } if (imageNames.Length > 0) { imageNames = imageNames.Remove(imageNames.Length - 1, 1); } string sqlUpdateUrl = string.Format("update T_ARTICLE set ArtUrl='{0}',ArtContent='',ArtImages='{3}' where ArtType={1} and ArtOrder={2}", id, artType, maxOrder, imageNames); isSuc = SqlServerHooker.UpdateDataToTable(sqlUpdateUrl); if (isSuc) { div_text.InnerText = isUpdateSuc.ToString() + "发布成功!"; gvArtManager.DataBind(); } else { div_text.InnerText = "发布失败!"; } }