protected void btnupload_Click(object sender, EventArgs e) { if (Page.IsValid) { try { if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString()) { Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString()); ReturnClass.ReturnBool rb = new ReturnClass.ReturnBool(); Utilities util = new Utilities(); Int32 maxLimit = 10485760; string content_type; if (FileUpload1.HasFile) { string ext = System.IO.Path.GetExtension(FileUpload1.FileName); double size = FileUpload1.PostedFile.ContentLength; string contenttype = FileUpload1.PostedFile.ContentType.ToLower(); if (FileUpload1.PostedFile.ContentLength > maxLimit) { Utilities.MessageBoxShow("File Is too Big...Maximum Size allowed is 5 Mb"); } else if (contenttype == "image/png" || contenttype == "image/jpg" || contenttype == "image/jpeg") { try { bl.File_extn = Path.GetExtension(FileUpload1.PostedFile.FileName).ToString(); Stream fs = default(Stream); fs = FileUpload1.PostedFile.InputStream; BinaryReader br1 = new BinaryReader(fs); bl.Document_data = br1.ReadBytes(FileUpload1.PostedFile.ContentLength); // FileUpload1.SaveAs(Server.MapPath("images/use_img.png")); if (Session["User_Id"] != null) { bl.User_id = Session["User_Id"].ToString(); } else { if (Request.Cookies["User_Id"] != null) { Session["User_Id"] = Request.Cookies["User_Id"].Value; bl.User_id = Request.Cookies["User_Id"].Value; } } bl.Document_name = "Profile Picture"; bl.Client_id = util.GetClientIpAddress(this.Page); bl.Panjiyan_category_id = "pic"; if (ext == ".pdf") { bl.Mime_type = "application/pdf"; } else { bl.Mime_type = contenttype; } dt = dl.Getfileupload(bl); if (dt.table.Rows.Count > 0) { rb = dl.Update_Upload_details(bl); } else { rb = dl.Upload_details(bl); } if (rb.status == true) { Utilities.MessageBox_UpdatePanel(UpdatePanel2, "Document Upload Successfully"); } else { Utilities.MessageBoxShow("Document Upload Failed"); } GetFileUpload(); } catch (Exception ex) { Utilities.MessageBoxShow("File Can Not Be Saved"); } } else { Utilities.MessageBoxShow("Only .jpg .png .jpeg files are allowed, try again"); } } } else { Utilities.MessageBox_UpdatePanel(UpdatePanel2, " पेज रिफ्रेश करना वर्जित है "); } } catch (NullReferenceException) { // Utilities.MessageBox_UpdatePanel_Redirect(UpdatePanel2, "Your Session Has Expired Please Login Again", "../Logout.aspx"); } } }