/// <summary> /// Creates a directory to the path specified if it's found to be nonexistent. /// Returns a <see cref="DirectoryInfo"/> object for the directory created. /// </summary> /// <param name="path">The path of the directory.</param> /// <param name="directoryName"> /// Name of the directory. This will placed in the <see cref="IErrorDialogService"/> message showing /// the user which directory couldn't be created should an <see cref="Exception"/> be thrown. /// </param> private DirectoryInfo CreateDirectoryIfNonexistent(string path, string directoryName) { var message = String.Empty; DirectoryInfo directoryInfo = null; try { directoryInfo = DirectoryEx.CreateDirectoryIfNonexistent(path); } catch (PathTooLongException) { message = $"The \"{directoryName}\" directory couldn't be created because the resulting path would be too long."; ErrorDialogService.Show(message); } catch (UnauthorizedAccessException) { message = $"The \"{directoryName}\" directory couldn't be created because this application doesn't have access to the destination."; ErrorDialogService.Show(message); } catch (ArgumentException) { message = $"The \"{directoryName}\" directory couldn't be created because the path is prefixed with, or contains, only a colon character (:)."; ErrorDialogService.Show(message); } catch (DirectoryNotFoundException) { message = $"The \"{directoryName}\" directory couldn't be created because the path was invalid (for example, it's on an unmapped drive)."; ErrorDialogService.Show(message); } catch (IOException) { message = $"The \"{directoryName}\" directory couldn't be created because the specified path is a file, or the network name isn't known."; ErrorDialogService.Show(message); } catch (NotSupportedException) { message = $"The \"{directoryName}\" directory couldn't be created because the path contains a colon character (:) that is not part of a drive label."; ErrorDialogService.Show(message); } catch (Exception e) { Console.WriteLine(e.Message); ErrorDialogService.Show(e.Message); throw; } return(directoryInfo); }