/// <summary> /// Gets the book list titles file path. /// </summary> /// <returns>True if path found else False.</returns> public bool GetBookListTitlesFilePath() { var dirFileOp = new FileClass(); var validate = new ValidationClass(); var dirPath = BookListPathsProperties.PathTitlesDirectory; var fileName = BookListPathsProperties.NameTitlesBookListFile; var cls = new CombinePathsClass(); var filePath = cls.CombineDirectoryPathWithFileName( dirPath, fileName); var fileExists = validate.ValidateFileExists(filePath, true); if (!fileExists) { var dlgResult = this._msgBox.ShowQuestionMessageBox(); // Create directory if it does not exist. if (dlgResult == DialogResult.Yes) { dirFileOp.CreateNewFile(filePath); if (validate.ValidateFileExists(filePath, true)) { BookListPathsProperties.PathTitleNamesListFile = filePath; return(true); } else { // return no directory created. BookListPathsProperties.PathTitleNamesListFile = String.Empty; return(false); } } else { // return user does not want to create the directory. BookListPathsProperties.PathTitleNamesListFile = String.Empty; return(false); } } else { BookListPathsProperties.PathTitleNamesListFile = filePath; return(true); } }
/// <summary> /// Writes the Book Title to Authors file. /// </summary> /// <param name="filePath">The file path.</param> /// <param name="title">The Title to write.</param> /// <returns></returns> public bool WriteBookTitleToAuthorsFile(string filePath, string title) { if (!_validate.ValidateStringIsNotNull(title)) { return(false); } if (!_validate.ValidateStringHasLength(title)) { return(false); } if (!_validate.ValidateStringIsNotNull(filePath)) { return(false); } if (!_validate.ValidateStringHasLength(filePath)) { return(false); } if (!_validate.ValidateFileExists(filePath, true)) { return(false); } using (var writer = new StreamWriter(filePath, true)) { writer.WriteLine(title); } return(true); }