protected void Button1_Click(object sender, EventArgs e) { ds.Clear(); ds = db.discont("select fname from tb_upload where fname='" + TextBox1.Text + "'"); if (ds.Tables[0].Rows.Count != 0) { RegisterStartupScript("", "<script Language=JavaScript>alert('Filename Already Existed')</Script>"); } else { if (FileUpload1.HasFiles) { string path = "~/Employee/files/upload/" + FileUpload1.FileName; FileUpload1.SaveAs(MapPath(path)); string server_path = Server.MapPath(path); string extension = System.IO.Path.GetExtension(FileUpload1.FileName); if (extension == ".docx" || extension == ".doc") { data = read_doc.read_from_doc(server_path); } else if (extension == ".txt") { data = read_txtt.readtxt(server_path); } else if (extension == ".pdf") { data = read_pdf.pdfText(server_path); } ds.Clear(); string e_key = db.MakePwd(5); string token = db.MakePwd(3) + db.numpassword(3); ViewState["token"] = token; enc_string = cld.encrypt(data, e_key); string enc_path = Server.MapPath("~/Employee/files/efile/" + TextBox1.Text + ".txt"); File.WriteAllText(enc_path, enc_string); bool b = db.extnon("insert into tb_upload values('" + Session["user"].ToString() + "','" + TextBox1.Text + "','" + e_key + "','" + TextBox2.Text + "','0','0','" + DateTime.Now.ToString() + "','" + extension + "')"); bool d = db.extnon("insert into tb_role_policy values('" + TextBox1.Text + "','" + Session["role"] + "','0','" + token + "')"); if (b == true) { File.Delete(server_path); MultiView1.ActiveViewIndex = 1; } } else { RegisterStartupScript("", "<script Language=JavaScript>alert('Please Upload File')</Script>"); } } }
protected void Button1_Click(object sender, EventArgs e) { ds.Clear(); string e_key = db.extscalr("select ekey from tb_upload where fname='" + Session["fn"].ToString() + "'"); enc_string = cld.encrypt(TextBox1.Text, e_key); string enc_path = Server.MapPath("~/Employee/files/efile/" + Session["fn"].ToString() + ".txt"); File.WriteAllText(enc_path, enc_string); bool b = db.extnon("update tb_upload set e_status='2',date ='" + DateTime.Now.ToString() + "' where fname='" + Session["fn"].ToString() + "'"); if (b == true) { List <string> ls = new List <string>(); ds.Clear(); ds = db.discont("select roles from tb_role_policy where filename='" + Session["fn"].ToString() + "'"); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { ls.Add(ds.Tables[0].Rows[i]["roles"].ToString()); } for (int i = 0; i < ls.Count; i++) { ds.Clear(); ds = db.discont("select role from tb_login where role='" + ls[i].ToString() + "'"); if (ds.Tables[0].Rows.Count > 0) { mail ma = new mail(); ma.send_msg(" File modified :", Session["fn"].ToString()); break; } } TextBox1.Text = null; RegisterStartupScript("", "<script Language=JavaScript>alert('Successfully Uploaded')</Script>"); } }