/// <summary>
        /// validating the folder path
        /// </summary>
        /// <param name="FolderPath"></param>
        /// <param name="returnPath"></param>
        /// <returns></returns>
        public FolderPathErrorCode CheckFolderPath(string FolderPath, ref string returnPath)
        {
            if (string.IsNullOrEmpty(FolderPath) || string.IsNullOrWhiteSpace(FolderPath)) //checks whether the folder path is null or empty or white space
            {
                return(FolderPathErrorCode.FolderPath_Empty);
            }

            //else if (objAlphaPatternFolder.IsMatch(FolderPath)) // old implementation using regex
            else
            {
                FolderPathErrorCode errCode = FolderPathErrorCode.FolderPath_Empty;

                if (Directory.Exists(FolderPath)) //checks whether the folder path exists in the directory
                {
                    returnPath = FolderPath;
                    errCode    = FolderPathErrorCode.Success;
                }
                else
                {
                    // DirectoryInfo dirInf = new DirectoryInfo(FolderPath);
                    string [] folderNameArr = FolderPath.Split(Path.DirectorySeparatorChar);
                    string    folderName    = folderNameArr[folderNameArr.Length - 1];//dirInf.Name;
                    foreach (char folderPathCharItem in folderName)
                    {
                        foreach (char invalidCharItem in invalidCharsList)
                        {
                            if (folderPathCharItem.CompareTo(invalidCharItem) == 0)
                            {
                                errCode = FolderPathErrorCode.InvalidDirectory;
                                break;
                            }
                        }
                    }
                    if (errCode != FolderPathErrorCode.InvalidDirectory)
                    {
                        errCode = FolderPathErrorCode.DirectoryDoesnotExist;
                    }
                }
                return(errCode);
            }
        }
Exemplo n.º 2
0
        /// <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;
            }
            }
        }