/// <summary> /// Gets the list of all the files according to the search string /// if the search is true /// </summary> /// <param name="isSearchable"></param> /// <param name="searchTerm"></param> public void GetFileList(int isSearchable, string searchTerm) { DataTable dtFile = null; DataAccessLayer ObjData = null; try { ObjData = new DataAccessLayer(); //Get all the files uploaded by the logged in user. dtFile = ObjData.GetAllFiles(this.Master.CurrentUser.Id, this.Master.CurrentUser.IsAdmin, isSearchable, searchTerm); lvFile.DataSource = dtFile; lvFile.DataBind(); if (dtFile != null && dtFile.Rows.Count > 0) { lblNoData.Visible = false; } else { lblNoData.Visible = true; } } catch (Exception ex) { ErrorUtility.WriteError(ex); } finally { dtFile = null; ObjData = null; } }
/// <summary> /// Get called on page load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { if (this.Master.CurrentUser != null) { GetFileList(0, string.Empty); if (Session["FileId"] != null) { hdnFileIdTinyUrl.Value = Convert.ToString(Session["FileId"]); Session["FileId"] = null; ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", "SaveTinyUrl();", true); } } } } catch (Exception ex) { //Log the error ErrorUtility.WriteError(ex); } }
/// <summary> /// vaidation of the user /// </summary> /// <param name="email">email textbox's content</param> /// <param name="password">Password textbox's content</param> private void ValidateUser(string email, string password) { try { BusinessLogic objBusiness = new BusinessLogic(); bool isValidUser = objBusiness.ValidateUser(email, password, chkRememberMe.Checked); //Check if the email and password is a valid combination if (isValidUser) { //Redirects to the upload file page. System.Web.HttpContext.Current.Response.Redirect(ConstantUtility.UploadPage, false); } else { divErrorMessage.Visible = true; divErrorMessage.InnerHtml = ConstantUtility.UserValidationError; } } catch (Exception ex) { //log the error. ErrorUtility.WriteError(ex); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lvFile_ItemCommand(object sender, ListViewCommandEventArgs e) { int fileId = 0; BusinessLogic objBusiness = null; try { if (e.CommandArgument != null && e.CommandName.Equals("DownloadFile")) { int.TryParse(e.CommandArgument.ToString(), out fileId); objBusiness = new BusinessLogic(); bool isSuccess = objBusiness.DownloadFile(fileId); //File could not be downloaded if (!isSuccess) { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", ConstantUtility.DownloadError, true); } } } catch (Exception ex) { //Log the error ErrorUtility.WriteError(ex); } finally { objBusiness = null; } }
private void GetUserDetails() { //get the account details of the logged in user try { DataAccessLayer ObjData = new DataAccessLayer(); UserAccount objAccDetails = ObjData.GetAccountDetails(this.CurrentUser.Id); //Check if the record exists for the user if (objAccDetails != null) { lblFiles.Text = objAccDetails.TotalFiles + lblFiles.Text; lblTotalDownloads.Text = objAccDetails.TotalDownloads + lblTotalDownloads.Text; lblTotalSize.Text = objAccDetails.TotalSize + lblTotalSize.Text; } lblUserName.Text = this.CurrentUser.UserName; } catch (Exception Ex) { //log the error ErrorUtility.WriteError(Ex); } }
protected void btnLogOut_Click(object sender, EventArgs e) { try { System.Web.Security.FormsAuthentication.SignOut(); Session.Clear(); Session.Abandon(); //clear authentication cookie HttpCookie authCookie = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, ""); authCookie.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(authCookie); // clear session cookie (not necessary for your current problem but i would recommend you do it anyway) HttpCookie aspCookie = new HttpCookie("ASP.NET_SessionId", ""); aspCookie.Expires = DateTime.Now.AddYears(-1); Response.Cookies.Add(aspCookie); //Redirect to the login page Response.Redirect("Login.aspx", false); } catch (Exception Ex) { //Log the error ErrorUtility.WriteError(Ex); } }
/// <summary> /// For zipping the multiple files into a single file /// </summary> /// <param name="files"></param> /// <param name="fileSize"></param> /// <returns></returns> public string ZipFiles(HttpFileCollection files, out double fileSize, out string originalFileName, out string extension) { fileSize = 0.0; originalFileName = string.Empty; extension = string.Empty; string savedFileName = string.Empty; try { List <string> fileNames = new List <string>(); extension = ConstantUtility.Extensions.Zip; //Saving the files to the server foreach (string key in files) { HttpPostedFile file = files[key]; originalFileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')) + ConstantUtility.Extensions.Zip; savedFileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')) + "_" + Guid.NewGuid().ToString() + ConstantUtility.Extensions.Zip; fileNames.Add(file.FileName); fileSize += (double)file.ContentLength / 1024; string fileName = Path.Combine(IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.TempFolder]), file.FileName); file.SaveAs(fileName); } //Zipping the multiple files using (ZipFile zip = new ZipFile()) { for (int i = 0; i < fileNames.Count; i++) { zip.AddFile(Path.Combine(IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.TempFolder]), fileNames[i]), string.Empty); } zip.Save(Path.Combine(IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.FolderPath]), savedFileName)); } //Deleting the individual file from the server foreach (string name in fileNames) { string filePath = Path.Combine(IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.TempFolder]), name); File.Delete(filePath); } } catch (Exception ex) { //Log error ErrorUtility.WriteError(ex); } return(savedFileName); }
/// <summary> /// Save data in the session state /// </summary> /// <param name="email">user's email id.</param> /// <param name="userHashCode">user's unique id.</param> /// <param name="userName">First name and last name of the user</param> /// <param name="isAdmin">bool value to tell whether the user is admin or not</param> /// <param name="isRememberMe">bool value to tell whether to save data in cookies or not</param> public void SaveSession(User user, bool isRememberMe) { try { CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel(); serializeModel.Id = user.UserHashCode; serializeModel.UserName = user.UserName; serializeModel.IsAdmin = Convert.ToInt16(user.IsAdmin); JavaScriptSerializer serializer = new JavaScriptSerializer(); string userData = serializer.Serialize(serializeModel); FormsAuthenticationTicket authTicket = null; //If remember me is checked cookie is saved for 15 days if (isRememberMe) { authTicket = new FormsAuthenticationTicket( 1, user.EmailId, DateTime.Now, DateTime.Now.AddDays(15), false, userData); } else { authTicket = new FormsAuthenticationTicket( 1, user.EmailId, DateTime.Now, DateTime.Now.AddMinutes(15), false, userData); } string encTicket = FormsAuthentication.Encrypt(authTicket); HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket); System.Web.HttpContext.Current.Response.Cookies.Add(faCookie); //save the encrypted cookie value in the database BusinessLogic objBusiness = new BusinessLogic(); objBusiness.SaveSessionData(user.UserHashCode, encTicket); } catch (Exception ex) { //Log the error. ErrorUtility.WriteError(ex); } }
public bool RemoveFile(string fileId) { try { BusinessLogic objBusiness = new BusinessLogic(); return(objBusiness.DeleteFile(Convert.ToInt32(fileId))); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } }
public bool ChangeFilePassword(string newPassword, string oldPassword, string filePassword, string fileId) { try { BusinessLogic objBusiness = new BusinessLogic(); return(objBusiness.ChangeFilePassword(newPassword, oldPassword, filePassword, fileId)); } catch (Exception ex) { ErrorUtility.WriteError(ex); return(false); } }
public void UnlockFile(string fileId) { try { BusinessLogic objBusiness = new BusinessLogic(); objBusiness.UnlockFile(Convert.ToInt32(fileId)); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } }
public void DeleteFiles(string selectedRows) { try { BusinessLogic objBusiness = new BusinessLogic(); objBusiness.DeleteFiles(selectedRows); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } }
public bool ChangeName(string newFileName, string fileId) { try { BusinessLogic objBusiness = new BusinessLogic(); objBusiness.ChangeName(newFileName, Convert.ToInt32(fileId)); } catch (Exception Ex) { ErrorUtility.WriteError(Ex); } return(true); }
public bool UpdateTotalSpace(string userId, string colValue) { try { BusinessLogic objBusiness = new BusinessLogic(); return(objBusiness.UpdateTotalSpace(Convert.ToInt32(userId), colValue)); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } }
public bool LockFile(string filePassword, string fileId) { try { BusinessLogic objBusiness = new BusinessLogic(); objBusiness.LockFile(filePassword, Convert.ToInt32(fileId)); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } return(true); }
public string ViewPassword(string fileId) { string filePassword = null; try { BusinessLogic objBusiness = new BusinessLogic(); filePassword = objBusiness.ViewPassword(Convert.ToInt32(fileId)); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } return(filePassword); }
public string GetFileName(int fileId) { string fileName = null; try { BusinessLogic objBusiness = new BusinessLogic(); fileName = objBusiness.GetFileName(Convert.ToInt32(fileId)); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } return(fileName); }
/// <summary> /// validation for captcha /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ValidateCaptcha(object sender, ServerValidateEventArgs e) { try { SignUpCaptcha.ValidateCaptcha(txtCaptcha.Text.Trim()); e.IsValid = SignUpCaptcha.UserValidated; if (!e.IsValid) { invalidCaptcha = true; } } catch (Exception ex) { ErrorUtility.WriteError(ex); } }
protected void Page_Load(object sender, EventArgs e) { try { string fileId; fileId = HttpContext.Current.Request.QueryString["FileId"]; fileId = fileId.Replace(" ", "+"); //Page.ClientScript.RegisterClientScriptBlock(GetType(), "PushNotification", "PushNotification();", true); frmDownloadhandler.Attributes.Add("src", "DownLoadFile.aspx?FileId=" + fileId); fileId = IGroupUtility.Decrypt(fileId); hdnDownloadFileId.Value = fileId; } catch (Exception ex) { ErrorUtility.WriteError(ex); } }
public string GetAllUsersDetail(int numRows, int pageNumber, string sidx, string sord, string searchOper, string searchString) { string result = string.Empty; try { BusinessLogic objBusiness = new BusinessLogic(); result = objBusiness.GetAllUsersDetail(numRows, pageNumber, sidx, sord, searchOper, searchString); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } return(result); }
/// <summary> /// Saves the user details /// </summary> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="email"></param> /// <param name="password"></param> public void SaveUser(string firstName, string lastName, string email, string password) { try { BusinessLogic objBusiness = new BusinessLogic(); bool isSuccess = objBusiness.SaveUser(firstName, lastName, email, password); if (isSuccess) { dvSuccessfulAlert.Visible = true; dvRegister.Visible = false; } } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } }
public bool ResetPassword(string userHashCode, string currentPassword, string newPassword) { bool isSuccess = false; try { if (!string.Equals(userHashCode, string.Empty)) { BusinessLogic objBusiness = new BusinessLogic(); isSuccess = objBusiness.ResetPassword(userHashCode, currentPassword, newPassword); } } catch (Exception Ex) { ErrorUtility.WriteError(Ex); } return(isSuccess); }
public string SaveTinyUrl(string fileId) { string tinyUrl = string.Empty; BusinessLogic objBusiness = null; try { objBusiness = new BusinessLogic(); tinyUrl = objBusiness.SaveTinyUrl(fileId); } catch (Exception ex) { ErrorUtility.WriteError(ex); throw ex; } finally { objBusiness = null; } return(tinyUrl); }
/// <summary> /// This is used for resizing the images. /// </summary> /// <param name="originalFilepath"></param> /// <param name="thumbFileName"></param> public void ResizeImage(string originalFilepath, string thumbFileName) { Image FullsizeImage = null; try { int NewHeight = 1100; int NewWidth = 800; using (FullsizeImage = Image.FromFile(originalFilepath)) { // Prevent using images internal thumbnail FullsizeImage.RotateFlip(RotateFlipType.Rotate180FlipNone); FullsizeImage.RotateFlip(RotateFlipType.Rotate180FlipNone); if (FullsizeImage.Height > 500) { NewHeight = 1100; // Resize with height instead NewWidth = FullsizeImage.Width * NewHeight / FullsizeImage.Height; } } FullsizeImage.Dispose(); Dictionary <string, string> Versions = new Dictionary <string, string> { { "_Thumb", "width=96&height=72&format=png&dpi=150" } }; string thumbPath = System.IO.Path.Combine(IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.ThumbImagePath]), thumbFileName); ImageJob ObjImageJobThumbnail = new ImageJob(originalFilepath, thumbPath, new Instructions(Versions["_Thumb"])); ObjImageJobThumbnail.Build(); } catch (Exception ex) { ErrorUtility.WriteError(ex); } }
/// <summary> /// btnRegister click event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnRegister_Click(object sender, EventArgs e) { string password = string.Empty; string firstName = string.Empty; string lastName = string.Empty; string email = string.Empty; bool isUserExist = false; try { password = txtSignUpPassword.Text.Trim(); if (!invalidCaptcha) { firstName = txtFirstName.Text; lastName = txtLastName.Text; email = txtSignUpEmail.Text.ToLower(); BusinessLogic objBusiness = new BusinessLogic(); isUserExist = objBusiness.UserExist(email); if (!isUserExist) { //Add a new user SaveUser(firstName, lastName, email, password); } else { txtCaptcha.Text = string.Empty; divExistingUser.InnerHtml = ConstantUtility.ExistingUserError; } } } catch (Exception ex) { ErrorUtility.WriteError(ex); } }
/// <summary> /// click method for downloading a locked file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUnlock_ServerClick(object sender, EventArgs e) { BusinessLogic objBusiness = null; DataAccessLayer objData = null; try { objData = new DataAccessLayer(); int fileId = 0; int.TryParse(Convert.ToString(hdnFileId.Value), out fileId); UploadedFile fileDetails = objData.DownloadFile(fileId); string filePwd = hdnFilePassword.Value; //If the file password matches and the file is not deleted it gets downloaded if (fileDetails != null && string.Equals(filePwd, fileDetails.FilePassword) && !fileDetails.IsDeleted) { //download the file. objBusiness = new BusinessLogic(); objBusiness.DownloadFile(Convert.ToInt32(fileId), fileDetails); } else { ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "ShowModalBoxWithMessage();", true); } } catch (Exception Ex) { ErrorUtility.WriteError(Ex); } finally { objBusiness = null; objData = null; } }
protected void Page_Load(object sender, EventArgs e) { UploadedFile fileDetails = null; string fileId = string.Empty; try { if (!IsPostBack) { if (HttpContext.Current.Request.QueryString["id"] != null) { if (CurrentUser.IsAdmin == 1) { fileId = HttpContext.Current.Request.QueryString["id"]; Page.ClientScript.RegisterStartupScript(typeof(Page), "CloseConsent", "window.close();", true); } } else { fileId = HttpContext.Current.Request.QueryString["FileId"]; //Decrypt the file id fileId = fileId.Replace(" ", "+"); fileId = IGroupUtility.Decrypt(fileId); } hdnFileId.Value = fileId; DataAccessLayer objData = new DataAccessLayer(); //Get the name of the file. fileDetails = objData.DownloadFile(Convert.ToInt32(fileId)); if (fileDetails != null && fileDetails.IsLocked && !fileDetails.IsDeleted) { ScriptManager.RegisterStartupScript(this, GetType(), "myFunction", "ShowModalBox();", true); } else { string filePath = System.IO.Path.Combine( IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.FolderPath]), fileDetails.SavedFileName); //Check if the file is deleted or not by the user if ((fileDetails != null && !fileDetails.IsDeleted && System.IO.File.Exists(filePath)) || (CurrentUser != null && CurrentUser.IsAdmin == 1 && fileDetails != null && !fileDetails.IsAdminDeleted && System.IO.File.Exists(filePath))) { //download the file if the file exists. BusinessLogic objBusiness = new BusinessLogic(); objBusiness.DownloadFile(Convert.ToInt32(fileId), fileDetails); } else { ScriptManager.RegisterStartupScript(this, GetType(), "alertMessage", ConstantUtility.DownloadError, true); } } } else { hdnFilePassword.Value = txtFilePassword.Value; } } catch (Exception ex) { //Log the error ErrorUtility.WriteError(ex); } }
public void ProcessRequest(HttpContext context) { try { string machineName = System.Environment.MachineName; string ipAddress = HttpContext.Current.Request.UserHostAddress; int fileId = 0; string fileName = string.Empty; string originalFileName = string.Empty; string savedFileName = string.Empty; string thumbFileName = null; string extension = string.Empty; double fileSize = 0.0; BusinessLogic objBusiness = new BusinessLogic(); //if there is more than one file, zip it before uploading it if (context.Request.Files.Count > 1) { HttpFileCollection files = context.Request.Files; savedFileName = ZipFiles(files, out fileSize, out originalFileName, out extension); thumbFileName = objBusiness.ExtIconName(extension); } else if (context.Request.Files.Count == 1) { HttpFileCollection files = context.Request.Files; foreach (string key in files) { HttpPostedFile file = files[key]; string guid = Guid.NewGuid().ToString(); fileName = file.FileName; //Get the index of the last dot(.) int indexOfExtension = fileName.LastIndexOf("."); //Get the file extension string fileExtension = fileName.Substring(indexOfExtension); //Get the file name with out extension string fileNameWithoutExtension = fileName.Substring(0, (fileName.Length - fileExtension.Length)); //Concat the file name with new guid fileName = string.Concat(fileNameWithoutExtension, "_", guid, fileExtension); //Get the new thumb file name thumbFileName = string.Concat(fileNameWithoutExtension, "_", guid, "_thumb", fileExtension); savedFileName = fileName; //Get the physical path, where the file will be saved. fileName = System.IO.Path.Combine(IGroupUtility.Decrypt(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.FolderPath]), fileName); extension = Path.GetExtension(fileName).Trim().ToLower(); originalFileName = file.FileName; //saving the file with a unique name. file.SaveAs(fileName); fileSize = ((double)file.ContentLength / 1024); } if (Convert.ToString(ConfigurationManager.AppSettings[ConstantUtility.ConfigKeys.ImageExtensions]).Contains(extension)) { ResizeImage(fileName, thumbFileName); } else { thumbFileName = objBusiness.ExtIconName(extension); } } DataAccessLayer objDataAccess = new DataAccessLayer(); if (objDataAccess != null) { fileId = objDataAccess.SaveFileDetails(originalFileName, savedFileName, CurrentUser.Id, machineName, ipAddress, fileSize, extension, thumbFileName); string fileEncryptedId = IGroupUtility.Encrypt(fileId.ToString()); //saving the data in session state. HttpContext.Current.Session["FileId"] = fileEncryptedId; } context.Response.Output.Write(ConstantUtility.True); } catch (Exception ex) { //Log error ErrorUtility.WriteError(ex); } }