private TreeNodeCollection AddFiles(string folder, FormDataCollection queryStrings) { var pickerApiController = new FileSystemPickerApiController(); //var str = queryStrings.Get("startfolder"); if (string.IsNullOrWhiteSpace(folder)) { return(null); } var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray(); var path = IOHelper.MapPath(folder); var rootPath = IOHelper.MapPath(queryStrings.Get("startfolder")); var treeNodeCollection = new TreeNodeCollection(); foreach (FileInfo file in pickerApiController.GetFiles(folder, filter)) { string nodeTitle = file.Name; string filePath = file.FullName.Replace(rootPath, "").Replace("\\", "/"); //if (file.Extension.ToLower() == ".gif" || file.Extension.ToLower() == ".jpg" || file.Extension.ToLower() == ".png") //{ // nodeTitle += "<div><img src=\"/umbraco/backoffice/FileSystemPicker/FileSystemThumbnailApi/GetThumbnail?width=150&imagePath="+ HttpUtility.UrlPathEncode(filePath) +"\" /></div>"; //} TreeNode treeNode = CreateTreeNode(filePath, path, queryStrings, nodeTitle, "icon-document", false); treeNodeCollection.Add(treeNode); } return(treeNodeCollection); }
private TreeNodeCollection AddFiles(string folder, FormDataCollection queryStrings) { var pickerApiController = new FileSystemPickerApiController(); //var str = queryStrings.Get("startfolder"); if (string.IsNullOrWhiteSpace(folder)) return null; var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray(); var path = IOHelper.MapPath(folder); var rootPath = IOHelper.MapPath(queryStrings.Get("startfolder")); var treeNodeCollection = new TreeNodeCollection(); foreach (FileInfo file in pickerApiController.GetFiles(folder, filter)) { string nodeTitle = file.Name; string filePath = file.FullName.Replace(rootPath, "").Replace("\\", "/"); //if (file.Extension.ToLower() == ".gif" || file.Extension.ToLower() == ".jpg" || file.Extension.ToLower() == ".png") //{ // nodeTitle += "<div><img src=\"/umbraco/backoffice/FileSystemPicker/FileSystemThumbnailApi/GetThumbnail?width=150&imagePath="+ HttpUtility.UrlPathEncode(filePath) +"\" /></div>"; //} TreeNode treeNode = CreateTreeNode(filePath, path, queryStrings, nodeTitle, "icon-document", false); treeNodeCollection.Add(treeNode); } return treeNodeCollection; }
private TreeNodeCollection AddFolders(string parent, FormDataCollection queryStrings) { var pickerApiController = new FileSystemPickerApiController(); var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray(); var treeNodeCollection = new TreeNodeCollection(); var startFolderName = queryStrings.Get("startfolder"); var startFolderPath = startFolderName.TrimStart(new char[] { '~', '/' }).EnsureStartsWith("~/"); IEnumerable <TreeNode> treeNodeList = pickerApiController.GetFolders(parent, filter) .Select(dir => CreateTreeNode(String.Format("{0}{1}", startFolderName, dir.FullName.Replace(IOHelper.MapPath(startFolderPath), "").Replace("\\", "/")), parent, queryStrings, dir.Name, "icon-folder", true)); //filter[0] == "." ? // dir.EnumerateDirectories().Any() || pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any() : // pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any()) treeNodeCollection.AddRange(treeNodeList); return(treeNodeCollection); }
private TreeNodeCollection AddFiles(string folder, FormDataCollection queryStrings) { var pickerApiController = new FileSystemPickerApiController(); //var str = queryStrings.Get("startfolder"); if (string.IsNullOrWhiteSpace(folder)) { return(null); } var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray(); var path = IOHelper.MapPath(folder); string startFolder = queryStrings.Get("startfolder"); var rootPath = IOHelper.MapPath(startFolder.EnsureStartsWith("/")); var treeNodeCollection = new TreeNodeCollection(); foreach (FileInfo fileInfo in pickerApiController.GetFiles(folder, filter)) { string nodeTitle = fileInfo.Name; //string filePath = file.FullName.Replace(rootPath, "").Replace("\\", "/"); string filePath = string.Format("{0}/{1}", folder, fileInfo.Name); TreeNode treeNode = CreateTreeNode(filePath, folder, queryStrings, nodeTitle, "icon-document", false); treeNodeCollection.Add(treeNode); } return(treeNodeCollection); }
private TreeNodeCollection AddFolders(string parent, FormDataCollection queryStrings) { var pickerApiController = new FileSystemPickerApiController(); var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray(); var treeNodeCollection = new TreeNodeCollection(); treeNodeCollection.AddRange(pickerApiController.GetFolders(parent, filter) .Select(dir => CreateTreeNode(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), parent, queryStrings, dir.Name, "icon-folder", filter[0] == "." ? dir.EnumerateDirectories().Any() || pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any() : pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any()))); return treeNodeCollection; }
private TreeNodeCollection AddFolders(string parent, FormDataCollection queryStrings) { var pickerApiController = new FileSystemPickerApiController(); var filter = queryStrings.Get("filter").Split(',').Select(a => a.Trim().EnsureStartsWith(".")).ToArray(); var treeNodeCollection = new TreeNodeCollection(); treeNodeCollection.AddRange(pickerApiController.GetFolders(parent, filter) .Select(dir => CreateTreeNode(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), parent, queryStrings, dir.Name, "icon-folder", filter[0] == "." ? dir.EnumerateDirectories().Any() || pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any() : pickerApiController.GetFiles(dir.FullName.Replace(IOHelper.MapPath("~"), "").Replace("\\", "/"), filter).Any()))); return(treeNodeCollection); }
private IEnumerable<string> GetAllFilePaths(string[] filesOrFolders, out List<StatusWithMessage> errors) { errors = new List<StatusWithMessage>(); string rootOfApplication = IOHelper.MapPath("~/"); List<string> filePaths = new List<string>(); //the static files could have files or folders, we are sure at this point so we need to collect all of the //files. FileSystemPickerApiController fileSystemApi = new FileSystemPickerApiController(); foreach (string fileOrFolder in filesOrFolders) { if (String.IsNullOrEmpty(fileOrFolder)) continue; try { //Map the file path to the server. string fileOrFolderPath = IOHelper.MapPath(fileOrFolder); FileAttributes attr = System.IO.File.GetAttributes(fileOrFolderPath); //Check to see if its a folder if ((attr & System.IO.FileAttributes.Directory) == FileAttributes.Directory) { IEnumerable<FileInfo> filesInTheFolder = fileSystemApi.GetFilesIncludingSubDirs(fileOrFolderPath); filePaths.AddRange(filesInTheFolder.Select(x => { string directory = x.Directory.FullName.Replace(rootOfApplication, ""); directory = directory.Replace("\\", "/"); return directory + "/" + x.Name; })); } else { if (!System.IO.File.Exists(fileOrFolderPath)) { //File does not exist, continue and log the error. errors.Add(new StatusWithMessage(false, String.Format("Could not find file with the path {0}", fileOrFolderPath))); continue; } if (fileOrFolder.StartsWith("/")) { filePaths.Add(fileOrFolder.TrimStart('/')); } else { filePaths.Add(fileOrFolder); } } } catch(Exception e) { } } return filePaths; }