protected void btnLuu_Click(object sender, EventArgs e) { try { Cache.Remove("tintuc"); TinTuc tt = new TinTuc(); int LoaiTinTuc = rbtTroGiup.Checked ? 1 : 0; string relativePath = null; string path = Server.MapPath("../Upload/NewsImages"); if (fileAnhChinh.PostedFile.FileName != "") { if ((fileAnhChinh.PostedFile.ContentLength <= 100000) || (Common.LoaiNguoiDungID() == 3)) { string randomString = ""; path += "\\" + Common.NguoiDungID(); relativePath = "./Upload/NewsImages" + "/" + Common.NguoiDungID() + "/"; int pos = fileAnhChinh.PostedFile.FileName.LastIndexOf('\\'); string absolutePath = path + "\\" + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (File.Exists(absolutePath)) { randomString = DateTime.Now.Ticks + "_"; absolutePath = path + "\\" + randomString + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1); } Common.ResizeFromStream(absolutePath, 300, fileAnhChinh.PostedFile.InputStream); //fileAnhChinh.PostedFile.SaveAs(absolutePath); relativePath += randomString + fileAnhChinh.PostedFile.FileName.Remove(0, pos + 1); if (Request.QueryString["nid"] == null) { tt.InsertFields(txtTieuDe.Text, wheNoiDung.TextXhtml, txtTomTat.Text, Common.NguoiDungID(), DateTime.Now, relativePath, LoaiTinTuc); } else { tt.UpdateFields(Convert.ToInt32(Request.QueryString["nid"]), txtTieuDe.Text, wheNoiDung.Text, txtTomTat.Text, Common.NguoiDungID(), DateTime.Now, relativePath, LoaiTinTuc); } imgAnhChinh.ImageUrl = "." + relativePath; } else { lblAnhChinhErr.Text = "Kích cỡ ảnh quá lớn!"; return; } } else { if (Request.QueryString["nid"] == null) { tt.InsertFields(txtTieuDe.Text, wheNoiDung.TextXhtml, txtTomTat.Text, Common.NguoiDungID(), DateTime.Now, relativePath, LoaiTinTuc); } else { tt.UpdateFields(Convert.ToInt32(Request.QueryString["nid"]), txtTieuDe.Text, wheNoiDung.Text, txtTomTat.Text, Common.NguoiDungID(), DateTime.Now, relativePath, LoaiTinTuc); } } } catch (Exception ex) { Response.Redirect("../message.aspx?msg=" + ex.Message.Replace("\r\n", ""), false); } string strScript = "<script language='JavaScript'>" + "window.parent.RefreshNews();</script>"; ClientScript.RegisterStartupScript(GetType(), "Refresh", strScript); }