void AsyncFileUpload1_UploadedComplete(object sender, AsyncFileUploadEventArgs e) { try { string path = ""; string urlFile = ""; if (Path.GetExtension(e.filename).Contains(".pdf") == false && Path.GetExtension(e.filename).Contains(".zip") && Path.GetExtension(e.filename).Contains(".rar")) { return; } SqlFunction sqlFun = new SqlFunction(HttpContext.Current.Session.GetConnectionString2()); //lấy mã dự án //string maDuAn = sqlFun.GetOneStringField("select maDuAn from tblDuAn where sttDuAnpr = N'" + hdfSttDA.Value + "'"); string tenFile = e.filename;//"VanBan" + hdfSTTVanBan.Value + ".pdf"; if (!System.IO.Directory.Exists(Server.MapPath("~/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + userControlVanBanChucNang.Value.ToString().Split('_')[0].ToString()))) { System.IO.Directory.CreateDirectory(Server.MapPath("~/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + userControlVanBanChucNang.Value.ToString().Split('_')[0].ToString())); } string strDate = DateTime.Now.ToString("dd_MM_yy_hhmmss"); string fileExtension = Path.GetExtension(tenFile).Replace(".", ""); tenFile = tenFile.Substring(tenFile.LastIndexOf("\\\\") + 1); tenFile = tenFile.Substring(0, tenFile.LastIndexOf(fileExtension)) + strDate + "." + fileExtension; tenFile = tenFile.Replace(" ", ""); path = string.Concat(Server.MapPath("/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + userControlVanBanChucNang.Value.ToString().Split('_')[0].ToString() + "/" + tenFile + "")); if (!System.IO.File.Exists(path)) { System.IO.File.Delete(path); AsyncFileUpload1.SaveAs(path); urlFile = "/VanBan/" + HttpContext.Current.Session.GetDonVi().maDonVi + "/" + userControlVanBanChucNang.Value.ToString().Split('_')[0].ToString() + "/" + tenFile + ""; sqlFun.ExeCuteNonQuery("UPDATE dbo.tblVanBanDA SET tenFile=N'" + urlFile + "' WHERE sttVBDApr='" + userControlVanBanpr.Value.ToString() + "'"); AsyncFileUpload1.ClearState(); AsyncFileUpload1.Dispose(); return; } else { //Xoa file neu da ton tai System.IO.File.Delete(path); AsyncFileUpload1_UploadedComplete(sender, e); } } catch { } AsyncFileUpload1.Dispose(); }