private void AddUserFolder(ref DirectoryItem[] directories, bool loadFiles) { var usersMainFolder = directories.SingleOrDefault(d => d.Name.ToUpper() == "USERS"); if (usersMainFolder != null) { var userFolder = FolderManager.Instance.GetUserFolder(CurrentUser); usersMainFolder.Name = FolderManager.Instance.MyFolderName; string endUserPath = (string)FileSystemValidation.ToEndUserPath(userFolder.FolderPath); usersMainFolder.FullPath = endUserPath; var folderPermissions = PathPermissions.Read; if (DNNValidator.CanViewFilesInFolder((FolderInfo)userFolder)) { if (DNNValidator.CanAddToFolder((FolderInfo)userFolder)) { folderPermissions = folderPermissions | PathPermissions.Upload; } if (DNNValidator.CanDeleteFolder((FolderInfo)userFolder)) { folderPermissions = folderPermissions | PathPermissions.Delete; } } usersMainFolder.Permissions = folderPermissions; //var showFiles = new ArrayList(); //if (loadFiles) //{ // var files = FolderManager.Instance.GetFiles((FolderInfo)userFolder); // foreach (var fileInfo in files) // { // showFiles.Add(new FileItem(fileInfo.FileName, fileInfo.Extension, fileInfo.Size, "", FileManager.Instance.GetUrl(fileInfo), "", folderPermissions)); // } //} //var folderFiles = (FileItem[]) showFiles.ToArray(typeof (FileItem)); //var newDirectory = new DirectoryItem(userFolder.DisplayName, "", endUserPath, "", folderPermissions, folderFiles, new DirectoryItem[0]); } }
private DirectoryItem[] AddChildDirectoriesToList(ref DirectoryItem[] radDirectories, bool recursive, bool loadFiles) { var newDirectories = new ArrayList(); var invalidFolders = new List <DirectoryItem>(); foreach (var radDirectory in radDirectories) { System.Diagnostics.Debug.WriteLine(DateTime.Now.ToLongTimeString() + " AddChildDirectoriesToList " + radDirectory.Name); var endUserPath = (string)FileSystemValidation.ToEndUserPath(radDirectory.FullPath); var folderPath = radDirectory.FullPath.EndsWith("/") ? radDirectory.FullPath : radDirectory.FullPath + "/"; var dnnFolder = DNNValidator.GetUserFolder(folderPath); if (dnnFolder == null) { invalidFolders.Add(radDirectory); continue; } //Don't show protected folders if (!string.IsNullOrEmpty(dnnFolder.FolderPath) && dnnFolder.IsProtected) { invalidFolders.Add(radDirectory); continue; } //Don't show Cache folder if (dnnFolder.FolderPath.ToLowerInvariant() == "cache/") { invalidFolders.Add(radDirectory); continue; } var showFiles = new ArrayList(); var folderPermissions = PathPermissions.Read; if (DNNValidator.CanViewFilesInFolder(dnnFolder)) { if (DNNValidator.CanAddToFolder(dnnFolder)) { folderPermissions = folderPermissions | PathPermissions.Upload; } if (DNNValidator.CanDeleteFolder(dnnFolder)) { folderPermissions = folderPermissions | PathPermissions.Delete; } if (loadFiles) { var files = FolderManager.Instance.GetFiles(dnnFolder); foreach (var fileInfo in files) { showFiles.Add(new FileItem(fileInfo.FileName, fileInfo.Extension, fileInfo.Size, "", GetFileUrl(fileInfo), "", folderPermissions)); } } var folderFiles = (FileItem[])showFiles.ToArray(typeof(FileItem)); //Root folder name var dirName = radDirectory.Name; if (dnnFolder.FolderPath == "" && dnnFolder.FolderName == "") { dirName = FileSystemValidation.EndUserHomeDirectory; } DirectoryItem newDirectory; if (recursive) { var directory = TelerikContent.ResolveRootDirectoryAsTree(radDirectory.Path); var tempVar2 = directory.Directories; if (dnnFolder.FolderPath == "" && dnnFolder.FolderName == "") //Replace USERS folder by the particular User Folder { AddUserFolder(ref tempVar2, loadFiles); } AddChildDirectoriesToList(ref tempVar2, false, false); newDirectory = new DirectoryItem(dirName, "", endUserPath, "", folderPermissions, folderFiles, tempVar2); radDirectory.Directories = tempVar2; } else { newDirectory = new DirectoryItem(dirName, "", endUserPath, "", folderPermissions, folderFiles, new DirectoryItem[0]); } newDirectories.Add(newDirectory); } else { invalidFolders.Add(radDirectory); } } //remove invalid folders radDirectories = radDirectories.Where(d => !invalidFolders.Contains(d)).ToArray(); return((DirectoryItem[])newDirectories.ToArray(typeof(DirectoryItem))); }