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

Thumbnails with CustomContentProvider

1 Answer 42 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Fit2Page asked on 22 Oct 2012, 09:48 AM
In our CMS I use the ResolveDirectory override to create custom resized thumbnails in the FileExplorer's ListView.

It is a problem when the folder contains lots of files (sometimes > 5000), these files are all resized directly on the first page.
How would I create a function which resizes only the files which are on the current page?
I tried to use the GetFile override but to no avail, this one doesn't seem to be triggered when browsing the files.

Any suggestions?

Marc

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 25 Oct 2012, 01:05 PM
Hi Marc,

Please accept my sincere apologies for the delayed answer.

In order to handle the resizing of the images just in the current page you need to have information about the current page, as well as for the set FileExplorer's PageSize.

The index of the first FileItem in the current page is given as a parameter in the  CallBack response, so you could access it in this way:
if (Request.Params["__CALLBACKID"] == RadFileExplorer1.UniqueID)
{
    System.Web.Script.Serialization.JavaScriptSerializer JSSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
    Dictionary<string, string> callbackparams = (Dictionary<string, string>)JSSerializer.Deserialize(Request.Params["__CALLBACKPARAM"], typeof(Dictionary<string, string>));
    startIndex = int.Parse(callbackparams["startIndex"]);
}

After that, you will need to subclass the existing FileSystemContentProvider and to override the ResolveDirectory()  method by adding there your thumbnails-creation logic.
public override DirectoryItem ResolveDirectory(string path)
{
    //Access the files from the current directory
    DirectoryItem orgDir = base.ResolveDirectory(path);
    //Access the nested directories from the current one
    DirectoryItem orgDir2 = ResolveRootDirectoryAsTree(path);
     
    //Get a reference to the page
    Page _pageContainsRadFileExplorer = HttpContext.Current.Handler as Page;
    RadFileExplorer fileExplorer = _pageContainsRadFileExplorer.FindControl("RadFileExplorer1") as RadFileExplorer;
 
    int dirCount = orgDir2.Directories.Length;
    int pageSize = fileExplorer.FileList.PageSize;
    int index = dirCount;
 
    foreach (FileItem file in orgDir.Files)
    {
        if (index > startIndex + pageSize) break;
        if (startIndex < dirCount && index < dirCount)
            index = dirCount;
         
        file.Name = index + "_" + file.Name; //A little visible change to the files just for testing:
         
        //Add your Thumbnail-creation logic here
        //
        //
 
        index++;
    }
        return orgDir;
}

For your convenience I have attached a sample project demonstrating the described scenario.

Regars,
Vesi
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
FileExplorer
Asked by
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Vessy
Telerik team
Share this question
or