This is a migrated thread and some comments may be shown as answers.

hiding hidden directories

1 Answer 113 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 26 Sep 2016, 02:21 PM

Hi I have been able to hide hidden files but i cant seem to get the directories to hide my files code is -

public override DirectoryItem ResolveDirectory(string virtualPath)
{

        DirectoryItem basedir = base.ResolveDirectory(virtualPath);
    
     

        string physicalPath;
physicalPath = this.GetPhysicalFromVirtualPath(virtualPath);

if (physicalPath == null)
return null;

DirectoryItem result = new DirectoryItem(PathHelper.GetDirectoryName(physicalPath),
virtualPath,
virtualPath,
virtualPath,
GetPermissions(physicalPath),
GetFiles(virtualPath),
new DirectoryItem[] { }// Directories are added in ResolveRootDirectoryAsTree method
);

        // Update all file items with the additional information (date, owner)
        DirectoryItem oldItem = base.ResolveDirectory(physicalPath);
        List<FileItem> visibleFiles = new List<FileItem>();
        foreach (FileItem fileItem in result.Files)
        {
            // Get the information from the physical file
            FileInfo fInfo = new FileInfo(physicalPath + "\\" + fileItem.Name);
            // Add the information to the attributes collection of the item. It will be automatically picked up by the FileExplorer
            // If the name attribute matches the unique name of a grid column
            fileItem.Attributes.Add("CreationDate", fInfo.CreationTimeUtc.ToString());
            fileItem.Attributes.Add("ModifiedDate", fInfo.LastWriteTime.ToString());

            
            
            FileAttributes fileattr = File.GetAttributes(physicalPath + "\\" + fileItem.Name);
            if((fileattr & FileAttributes.Hidden) != FileAttributes.Hidden)
            {
                visibleFiles.Add(fileItem);
            }
        }

        DirectoryItem result1 = new DirectoryItem(PathHelper.GetDirectoryName(physicalPath),
                                                    virtualPath,
                                                    virtualPath,
                                                    virtualPath,
                                                    GetPermissions(physicalPath),
                                                   visibleFiles.ToArray(),
                                                    new DirectoryItem[] { }// Directories are added in ResolveRootDirectoryAsTree method
                                                );

        return result1;
}

 

Which works really well my Directory code is code is - > 

   public override DirectoryItem ResolveRootDirectoryAsTree(string path)
{

        
        

        string physicalPath;
string virtualPath = string.Empty;       

if (PathHelper.IsSharedPath(path) || PathHelper.IsPhysicalPath(path))
{
physicalPath = path;

foreach (KeyValuePair<string, string> mappedPath in MappedPaths)
{

if (physicalPath.StartsWith(mappedPath.Value, StringComparison.CurrentCultureIgnoreCase))
{


string restOfPhysicalPath = physicalPath.Substring(mappedPath.Value.Length);


virtualPath = mappedPath.Key + restOfPhysicalPath.Replace('\\', '/');


virtualPath = PathHelper.AddEndingSlash(virtualPath, '/');
break;
}
}
}
else
{
virtualPath = PathHelper.AddEndingSlash(path, '/');
physicalPath = this.GetPhysicalFromVirtualPath(path);
           
if (physicalPath == null)
return null;
}

      


        DirectoryItem result = new DirectoryItem(PathHelper.GetDirectoryName(physicalPath),
string.Empty,
virtualPath,
string.Empty,
GetPermissions(physicalPath),
new FileItem[] { }, // Files are added in the ResolveDirectory method
GetDirectories(virtualPath)
);

        return result;
}

 

Any help would be much appreciated.

1 Answer, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 29 Sep 2016, 05:11 AM

Hello Paul,

 

Basically, you should handle that in the ResolveRootDirectoryAsTree method (as seggested in this post: http://www.telerik.com/forums/radfileexplorer-and-hidden-folders#2jrGnmFt_kO1L21RRzVMXQ) and programmatically filter the hidden folders so that they are not added to the Directories collection. 

 

A basic filtering logic for folders is available here: http://www.telerik.com/support/kb/aspnet-ajax/fileexplorer/details/hide-certain-directories-and-files-in-radfileexplorer

 

Regards,
Ianko
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
FileExplorer
Asked by
Paul
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Share this question
or