/// ******************************************************************************** /// <summary> /// Check if file exists if not stop execution by thrown exception. /// </summary> /// <param name="filePath">The file path to validate exists.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateFileExits(string filePath) { try { if (!File.Exists(filePath)) { throw new FileNotFoundException(); } } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate file for this path. Exiting operation: " + filePath; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
/// ******************************************************************************** /// <summary> /// Check the string for length if zero then exit operation. /// </summary> /// <param name="value"></param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateStringHasLength(string value) { try { if (value.Length == 0) { throw new NotSupportedException(); } } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "This value is not valid. It has no length. Exiting operation. " + value; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
/// ******************************************************************************** /// <summary> /// If directory does not exist stop operation. /// </summary> /// <param name="dirPath">The path of the directory to check.</param> /// <created>art2m,6/6/2019</created> /// <changed>art2m,6/6/2019</changed> /// ******************************************************************************** public static void ValidateDirectoryExists(string dirPath) { try { if (!Directory.Exists(dirPath)) { throw new DirectoryNotFoundException(); } } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "A directory in this path does not exist. Exiting operations. " + dirPath; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); } }
/// ******************************************************************************** /// <summary> /// Combine four strings to get complete path to directory First Directory must /// all ready exist. Check to see if directory path exists if so return path string. /// else create new directory and return path string. /// </summary> /// <param name="first">Directory name or path.</param> /// <param name="second">Directory name or path.</param> /// <param name="third">Directory name or path.</param> /// <param name="fourth">Directory name or path.</param> /// <returns></returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static string CombineStringsMakeDirectoryPath(string first, string second, string third, string fourth) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var makePath = Path.Combine(first, second); makePath = Path.Combine(makePath, third); makePath = Path.Combine(makePath, fourth); var dirPath = CheckDirectoryExistsCreateDirectory(makePath); return(dirPath); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "One or both of the path strings is null."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(string.Empty); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Possible invalid characters in path string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(string.Empty); } }
/// ******************************************************************************** /// <summary> /// Create user sub directory in Art2MSpell directory. This will hold all of /// this users spelling lists. /// </summary> /// <param name="dirPath">The path to the users directory.</param> /// <returns>True if user directory created else false.</returns> /// <created>art2m,5/22/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool CreateUserSpellingListDirectory(string dirPath) { var dirName = SpellingPropertiesClass.UserName; try { dirPath = Path.Combine(dirPath, dirName); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } return(Directory.Exists(dirPath)); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "One or both directory path strings are null. Make sure you are in the" + " list of users"; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The directory path is to long. Check path to user folder."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Not supported for this platform."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Encountered error while creating directory."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(false); } }
/// ******************************************************************************** /// <summary> /// Combine directory name with file name. Check to see if file exists if it does /// return file path else create file. /// </summary> /// <param name="dirPath">Directory path to join with file name.</param> /// <param name="fileName">The file name to create.</param> /// <returns>File path if exists or is created. else return empty string.</returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static string CombineDirectoryPathFileNameCheckCreateFile(string dirPath, string fileName) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var filePath = Path.Combine(dirPath, fileName); if (!File.Exists(filePath)) { File.Create(filePath).Dispose(); } return(!File.Exists(filePath) ? string.Empty : filePath); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The directory path is to long."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Not supported for this platform."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Encountered error while creating directory."; MyMessagesClass.ShowErrorMessageBox(); System.Diagnostics.Debug.WriteLine(ex.ToString()); return(string.Empty); } }
/// ******************************************************************************** /// <summary> /// If adding new user then write there name to the Art2MSpell user names file. /// </summary> /// <returns>True if write successful else false.</returns> /// <created>art2m,5/17/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool WriteUserNameFile(string filePath) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { // Append line to the file. using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine(SpellingPropertiesClass.UserName); } return(true); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Write spelling words list to file. /// </summary> /// <param name="filePath">Path to write file to.</param> /// <returns>True if file is written else false.</returns> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool WriteSpellingWordsToFile(string filePath) { var swc = new SpellingWordsCollection(); try { StreamWriter fileWrite; using (fileWrite = new StreamWriter(filePath, false)) { var cnt = swc.ItemsCount(); fileWrite.WriteLine(SpellingPropertiesClass.GetArt2MSpellHeader); Debug.WriteLine(SpellingPropertiesClass.GetArt2MSpellHeader); for (var i = 0; i < cnt; i++) { var word = swc.GetItemAt(i); fileWrite.WriteLine(word); } } return(true); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Reads file that contains all of the paths To users spelling List file. /// </summary> /// <returns>True if file read is successful.</returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool ReadUsersSpellingListPathsFile(string filePath) { try { if (!File.Exists(filePath)) { return(false); } using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { UsersNameCollection.AddItem(user.Trim()); } } return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Reads the spelling list from the file the user has opened. /// </summary> /// <param name="filePath">The file path to the spelling list user wishes to open.</param> /// <returns>True if the spelling list words are added to collection else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool ReadSpellingListFile(string filePath) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; var swc = new SpellingWordsCollection(); try { swc.ClearCollection(); using (var fileRead = new StreamReader(filePath)) { string word; while ((word = fileRead.ReadLine()) != null) { ValidateWordFromSpellingListAddToCollection(word); } } return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Write spelling words list to file. /// </summary> /// <param name="filePath">Path to write file to.</param> /// <param name="words"></param> /// <returns>True if file is written else false.</returns> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool WriteSpellingWordsToFile(string filePath, IEnumerable <string> words) { var wordsCsv = string.Join(",", words.ToArray()); try { File.WriteAllText(filePath, wordsCsv); return(true); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have access writes for this operation."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Reads the spelling list from the file the user has opened. /// </summary> /// <param name="filePath">The file path to the spelling list user wishes to open.</param> /// <returns>True if the spelling list words are added to collection else false.</returns> /// <created>art2m,5/10/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static List <string> ReadSpellingListFile(string filePath) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { string[] spell; using (var fileRead = new StreamReader(filePath)) { spell = fileRead.ReadToEnd().Split(','); } return(new List <string>(spell)); } catch (OutOfMemoryException ex) { MyMessagesClass.ErrorMessage = "Not enough memory to continue. Try closing other windows."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(new List <string>(Array.Empty <string>())); } }
/// ******************************************************************************** /// <summary> /// OverWrite file using the User Collection after a user has been removed from /// the list. /// </summary> /// <param name="filePath"></param> /// <returns></returns> /// <created>art2m,5/28/2019</created> /// <changed>art2m,5/28/2019</changed> /// ******************************************************************************** private static bool OverWriteUserNameFile(string filePath) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; using (var writer = new StreamWriter(filePath, false)) { for (var index = 0; index < UsersNameCollection.ItemsCount(); index++) { writer.WriteLine(UsersNameCollection.GetItemAt(index)); } } return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The path variable contains a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "the file path is to long."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (SecurityException ex) { MyMessagesClass.ErrorMessage = "The operation has caused a security violation."; Debug.WriteLine(ex.ToString()); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }
/// ******************************************************************************** /// <summary> /// Creates directories if they do not exist in supplied path; /// </summary> /// <param name="dirPath">The path to create directories from.</param> /// <returns>Directory path if they exist or were created else returns empty string.</returns> /// <created>art2m,5/23/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static string CheckDirectoryExistsCreateDirectory(string dirPath) { try { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; if (Directory.Exists(dirPath)) { return(dirPath); } Directory.CreateDirectory(dirPath); return(dirPath); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "Encountered Error when combining directory paths or creating directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (UnauthorizedAccessException ex) { MyMessagesClass.ErrorMessage = "You do not have necessary security rating to perform this operation."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (PathTooLongException ex) { MyMessagesClass.ErrorMessage = "The directory path is to long."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (NotSupportedException ex) { MyMessagesClass.ErrorMessage = "Not supported for this platform."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "Encountered error while creating directory."; MyMessagesClass.ShowErrorMessageBox(); Debug.WriteLine(ex.ToString()); return(string.Empty); } }
/// ******************************************************************************** /// <summary> /// Read user name file into collection. /// so user can log in with there name. This /// is used to keep each users spelling list together so they can choose /// an all ready saved spelling list to practice. /// </summary> /// <returns></returns> /// <created>art2m,5/20/2019</created> /// <changed>art2m,5/23/2019</changed> /// ******************************************************************************** public static bool ReadUserNameFile(string filePath) { MyMessagesClass.NameOfMethod = MethodBase.GetCurrentMethod().Name; try { using (var reader = new StreamReader(filePath)) { string user; while ((user = reader.ReadLine()) != null) { Unc.AddItem(user.Trim()); } } return(true); } catch (ArgumentNullException ex) { MyMessagesClass.ErrorMessage = "The file path value is a null string. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (ArgumentException ex) { MyMessagesClass.ErrorMessage = "The file path value is an empty string."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (FileNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate this file. " + filePath; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (DirectoryNotFoundException ex) { MyMessagesClass.ErrorMessage = "Unable to locate the directory."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } catch (IOException ex) { MyMessagesClass.ErrorMessage = "File path has invalid characters in it."; Debug.WriteLine(ex.ToString()); MyMessagesClass.ShowErrorMessageBox(); return(false); } }