public static FileNameFolderPathValidator GetInstance() { if (fileNameFolderPathValidator == null) { fileNameFolderPathValidator = new FileNameFolderPathValidator(); } return(fileNameFolderPathValidator); }
/// <summary> /// To validate the folder path and file name /// </summary> private void validateFolderPathFileName() { Common.Validators.FileNameFolderPathValidator FileFolderValidator = Common.Validators.FileNameFolderPathValidator.GetInstance(); folderPath = folderPath.TrimStart(); // This is done fix defect 0001878 when empty spaces are added at the start of the folder location a crash was occuring which has been fixed by trimming the start of the string folderPath = folderPath.TrimStart(new char[] { '(', ')', '{', '}', '[', ']' }); // To remove Brackets of all types at the start of the folder path which results in a crash to fix defect 0001891 folderPath = folderPath.TrimEnd(new char[] { '(', ')', '{', '}', '[', ']' }); // To remove Brackets of all types at the end of the folder path which results in a crash to fix defect 0001891 errCode = FileFolderValidator.CheckFolderPath(folderPath, ref returnPath); switch (errCode) { case FolderPathErrorCode.Success: //when the folder path is valid { if (!FileFolderValidator.CheckFileName(fileName)) //checks whether the file name is valid or not { ImageSavingbtn(); if (OpenFolderLocation_cbx.Checked) // if checked. { System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(fileNames[0])); //opens the folder containing the file . First element of string array is opened.By Ashutosh 24-7-2017 } if (OpenFile_cbx.Checked) { foreach (string item in fileNames) { try { System.Diagnostics.Process.Start(item); //opens the file/s. By Ashutosh 24-7-2017 } catch (Exception ex) { throw; } } } } else { CustomMessageBox.Show(CustomFolderData["SaveAs_Warning_Text"] as string, CustomFolderData["SaveAs_Warning_Header"] as string, CustomMessageBoxIcon.Warning); } break; } case FolderPathErrorCode.InvalidDirectory: //when the folder path is invalid { DialogResult result = CustomMessageBox.Show(CustomFolderData["FolderPath_Warning_Text"] as string, CustomFolderData["FolderPath_Warning_Header"] as string, CustomMessageBoxIcon.Warning); this.DialogResult = System.Windows.Forms.DialogResult.None; break; } case FolderPathErrorCode.FolderPath_Empty: //when the folder path is empty { try { DialogResult result = CustomMessageBox.Show(CustomFolderData["FolderPath_Empty_Text"] as string, CustomFolderData["FolderPath_Warning_Header"] as string, CustomMessageBoxIcon.Warning); this.DialogResult = System.Windows.Forms.DialogResult.None; } catch (Exception ex) { throw; } break; } case FolderPathErrorCode.DirectoryDoesnotExist: { DialogResult result = CustomMessageBox.Show(CustomFolderData["DirectoryDoesnotExistWarning_Text"] as string, CustomFolderData["DirectoryDoesnotExist_Header"] as string, CustomMessageBoxButtons.YesNo, CustomMessageBoxIcon.Warning); if (result == System.Windows.Forms.DialogResult.Yes) { if (!FileFolderValidator.CheckFileName(fileName)) //checks whether the file name is valid or not { Directory.CreateDirectory(folderPath); returnPath = folderPath; ImageSavingbtn(); if (OpenFolderLocation_cbx.Checked) // if checked. { System.Diagnostics.Process.Start(System.IO.Path.GetDirectoryName(fileNames[0])); //opens the folder containing the file . First element of string array is opened.By Ashutosh 24-7-2017 } if (OpenFile_cbx.Checked) { foreach (string item in fileNames) { try { System.Diagnostics.Process.Start(item); //opens the file/s. By Ashutosh 24-7-2017 } catch (Exception ex) { throw; } } } } else { CustomMessageBox.Show(CustomFolderData["SaveAs_Warning_Text"] as string, CustomFolderData["SaveAs_Warning_Header"] as string, CustomMessageBoxIcon.Warning); } } break; } } }