public void AddUserFolder(string folderName) { var actualDirectory = HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + folderName); if (!Directory.Exists(actualDirectory)) { Directory.CreateDirectory(actualDirectory); } }
public string[] GetListOfUsers() { var listOfUser = new string[] { }; try { listOfUser = Directory.GetDirectories( HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory"))); } catch (FileNotFoundException e) { listOfUser[0] = "No users founded."; } return(listOfUser); }
public string DeleteBook(string fileToDelete, string activeUser) { var mssg = string.Empty; var pathToFile = string.Format( "{0}{1}/Books/{2}", GlobalVariables.ConfigResource("UsersDirectory"), activeUser, fileToDelete.Trim()); try { Directory.Delete(HttpContext.Current.Server.MapPath(pathToFile), true); } catch (IOException e) { mssg = e.Message; } return(mssg); }
public string[] GetListOfUserBooks(string user) { var directoriesPaths = new string[] { }; try { directoriesPaths = Directory.GetDirectories(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + user + "/Books/")); } catch (FileNotFoundException e) { directoriesPaths[0] = "No books found for this user"; } return(directoriesPaths); }
public string[] GetListOfTemplates() { string[] filesPaths = Directory.GetFiles(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("TemplateDirectory"))); return(filesPaths); }
public string AddNewBook(string newFileName, string userName) { var mssg = string.Empty; try { if ((newFileName != null) || (userName != string.Empty)) { var actualDirectory = HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + userName + "/Books/"); if (!Directory.Exists(actualDirectory + newFileName)) { Directory.CreateDirectory(actualDirectory + newFileName); } if ( !File.Exists(actualDirectory + newFileName + "/" + newFileName + ".xml")) { File.Copy( HttpContext.Current.Server.MapPath( GlobalVariables.ConfigResource("TemplateDirectory") + "empty.xml"), actualDirectory + newFileName + "/" + newFileName + ".xml"); File.Copy( HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("Images") + "noimage.jpg"), actualDirectory + newFileName + "/" + newFileName + ".jpg"); Directory.CreateDirectory( actualDirectory + newFileName + "/Generic/background/"); foreach (var dirName in GlobalVariables.GenericCharacterDirectory().SelectMany(genericCharDir => genericCharDir)) { Directory.CreateDirectory( actualDirectory + newFileName + "/Generic/character/" + dirName); } foreach (KeyValuePair <string, List <string[]> > genericChar2DDir in GlobalVariables.GenericCharacter2Directory()) { foreach (var dirName in genericChar2DDir.Value) { var rootDirectory = actualDirectory + newFileName + "/Generic/character2d/" + genericChar2DDir.Key + "/"; foreach (var subdirectory in dirName) { Directory.CreateDirectory(rootDirectory + subdirectory); } } } } else { throw new IOException("ERROR:This file exist already.Please!! Choose another name. "); } } else { throw new IOException("ERROR:File name cannot be empty "); } } catch (IOException e) { mssg = e.Message; } return(mssg); }
public List <BookModel> GetListOf2DCharacter(string bookName, string user) { var aListObjects = new List <BookModel>(); string[] directoryPaths = null; directoryPaths = Directory.GetDirectories(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + user + "/Books/" + bookName + GlobalVariables.ConfigResource("Character2DRes"))); if (directoryPaths.Length == 0) { return(aListObjects); } foreach (var directoryPath in directoryPaths) { var filesPaths = Directory.GetFiles(HttpContext.Current.Server.MapPath(directoryPath)); var lastFolderName = this.GetFolderName(directoryPath); var aBookModel = new BookModel { Target = lastFolderName }; if (filesPaths.Length != 0) { foreach (var aFile in filesPaths) { var aObject = new ObjectModel { ImageObj = aFile }; aBookModel.Objects.Add(aObject); aListObjects.Add(aBookModel); } } } return(aListObjects); }
public List <string> GetListOfUserBooksRelativePath(string user) { var physicalPaths = Directory.GetDirectories(HttpContext.Current.Server.MapPath(GlobalVariables.ConfigResource("UsersDirectory") + user + "/Books")); return(physicalPaths.Select(path => new FileInfo(path)).Select(fileInfo => fileInfo.Name).ToList()); }