Home / Community & Support / Knowledge Base / RadControls for ASP.NET and ASP.NET AJAX / FileExplorer / Use RadFileExplorer with physical and shared folder's paths

Use RadFileExplorer with physical and shared folder's paths

Article Info

Rating: 4

Article information

Article relates to

 RadFileExplorer Q3 2009 SP 1

Created by

 Fiko, Telerik

Last modified

 January 06, 2011

Last modified by

 Fiko



HOW TO

The basic steps needed to implement a custom provider, that works with files and folders from a physical (or shared) file system are shown in the attached demos. A GenericHandler.ashx is used in the examples in order to serve the files to the browser. The different file types should be handled in this .ASHX file in order to force the browser to download or open a file.

UPDATE
The provider supports shared folder's paths like "\\server.name\Path\Folder" as well. The mapping is done in the MappingFile.mapping file as shown in the attached demo.

THE MAIN PROBLEM

The main problem in this case is that we are working with physical paths that we do not want to pass (show) to the client. In the address bar of the RadFileExplorer we need to show custom paths, which uniquely identify the items in the FileExplorer (and on the server). In this case, a strong mapping between the physical path and the virtual path (that will be shown in the address bar) is necessary.
In the example, the mapping is specified in the MappingFile file. You can add another mapping in the .mapping file and then use the mapped physical paths in the ViewPath, DeletePath or UploadPath collections of the FileExplorer. In the demo, the GetPhysicalFromVirtualPath function is widely used, and this function gets the mapped physical path from the passed virtual path.

This is an example configuration using CustomFileSystemProvider:

protected void Page_Load(object sender, EventArgs e)
{
string[] viewPaths = new string[]
{
   @"C:\PhysicalSource\ROOT"
   @"\\Telerik.com\Path\SharedDir"
};
  
string[] uploadPaths = new string[]
{
   @
"C:\PhysicalSource\ROOT\CanUpload",
   @"\\Telerik.com\Path\SharedDir\ROOT\CanUpload"
};
  
string[] deletePaths = new string[] 
{
   @"C:\PhysicalSource\ROOT\Folder_1\CanDelete",
   @"
\\Telerik.com\Path\SharedDir\ROOT\Folder_1\CanDelete"
};
  
    RadFileExplorer1.Configuration.ViewPaths = viewPaths;
    RadFileExplorer1.Configuration.UploadPaths = uploadPaths;
    RadFileExplorer1.Configuration.DeletePaths = deletePaths;
    RadFileExplorer1.Configuration.SearchPatterns = new []{"*.*"};
    RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomFileSystemProvider).AssemblyQualifiedName;
}


When a custom provider is used, the security part needs to be implemented as well - for example : the upload and delete logic depending from the path set.


FORCE THE BROWSER TO DOWNLOAD THE FILES
 
A GenericHandler is used in order to serve the files to the browser. Please note that the different browsers handle the file types in a different manner. You can control browsers' action, specifying the Response.ContentType and adding a header with the Response.AddHeader method before writing the file to the browser. This is a common programming task and needs to be done in the used GenericHandler. The implemented code in the demo, forces the browser to download files with .jpg and .docx extensions.

USEFUL LINKS



NOTE
Please, read the comment in the beginning of the MoveDirectory function. Also, in the earlier versions of the control the CheckDeletePermissions method does not exist and needs to be removed. Also, a new method is added in the FileBrowserContentProvider - CheckReadPermissions (starting from version 2010.2.286) and It should be overridden as well in order to ensure that the content provider will work properly.

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.