/// <summary> /// Get folder and files /// </summary> /// <param name="pathType">Path type</param> /// <param name="fileInfo">FileInfo</param> private static List<FileDialog> GetFoldersFiles(string pathType, FileDialog fileInfo) { var filedialogs = new List<FileDialog>(); string path = fileInfo.Path; var sharePath = SharedPath(); if ((sharePath.Exists(p => p.Path == path) && fileInfo.Type == "root")) { filedialogs = sharePath; } else { //TODO: Folders list fetch from WCF var folders = GetFolders(path); var index = path.LastIndexOf(@"\", StringComparison.Ordinal); var folderPath = sharePath.Exists(p => p.Path == path) ? path : path.Substring(0, index); var type = sharePath.Exists(p => p.Path == path) ? "root" : "folder"; filedialogs.Add(new FileDialog {Name = "..(UP)", Path = folderPath, Type = type}); filedialogs.AddRange( folders.Select( folder => new FileDialog {Name = folder.Replace((path + @"\"), ""), Path = folder, Type = "folder"})); if (pathType == "file") { var files = GetFilePaths(path); filedialogs.AddRange( files.Select(file => new FileDialog {Name = file.Replace((path + @"\"), ""), Path = file, Type = "file"})); } } return filedialogs; }
public HttpResponseMessage PostGetFolderFilePath(string pathType,FileDialog fileInfo) { try { var filedialogs = GetFoldersFiles(pathType, fileInfo); return Request.CreateResponse<IEnumerable<FileDialog>>(HttpStatusCode.OK, filedialogs); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } }
public HttpResponseMessage PostGetFolderFilePathWithValidate(string pathType, FileDialog fileInfo) { try { var filedialogs = new List<FileDialog>(); if (IsValidateFilePath(fileInfo.Path, pathType)) { if (Path.HasExtension(fileInfo.Path)) { fileInfo.Path = fileInfo.Path.Substring(0, fileInfo.Path.LastIndexOf(@"\", System.StringComparison.Ordinal)); } filedialogs = GetFoldersFiles(pathType, fileInfo); } return Request.CreateResponse<IEnumerable<FileDialog>>(HttpStatusCode.OK, filedialogs); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } }