Thumbnails with CustomContentProvider

2 posts, 0 answers
  1. Fit2Page
    Fit2Page avatar
    345 posts
    Member since:
    Feb 2007

    Posted 22 Oct 2012 Link to this post

    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

  2. Vessy
    Admin
    Vessy avatar
    1389 posts

    Posted 25 Oct 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top