Apply changes to the files on the current page

1 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 07 Nov 2012 Link to this post


    RadControls version RadFileExplorer for ASP.NET AJAX from Q3 2012
    .NET version 3.5 / 4.0 / 4.5
    Visual Studio version 2008/ 2010/ 2012
    programming language C# / VB.NET
    browser support

    all browsers supported by RadControls

    How to apply changes to the files on the current loaded in FileExplorer folder page by page.

    In order to apply changes only to the files on the current page we need information about the current page, as well as for the set FileExplorer's PageSize.

    The start index of the first item on the current page is given as a parameter in the  CallBack response - it could be accessed in the following 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"]);

    If Not IsPostBack Then
        startIndex = 0
        If Request.Params("__CALLBACKID") = RadFileExplorer1.UniqueID Then
            Dim JSSerializer As New System.Web.Script.Serialization.JavaScriptSerializer()
            Dim callbackparams As Dictionary(Of String, String) = DirectCast(JSSerializer.Deserialize(Request.Params("__CALLBACKPARAM"), GetType(Dictionary(Of String, String))), Dictionary(Of String, String))
            startIndex = Integer.Parse(callbackparams("startIndex"))
        End If
    End If

    After that, we will subclass the existing FileSystemContentProvider by overriding the ResolveDirectory()  method:

    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
            //A custom file-change logic could be implemented here
        return orgDir;

    Public Overrides Function ResolveDirectory(path As String) As DirectoryItem
        'Access the files from the current directory
        Dim orgDir As DirectoryItem = MyBase.ResolveDirectory(path)
        'Access the nested directories from the current one
        Dim orgDir2 As DirectoryItem = ResolveRootDirectoryAsTree(path)
        'Get a reference to the page
        Dim _pageContainsRadFileExplorer As Page = TryCast(HttpContext.Current.Handler, Page)
        Dim fileExplorer As RadFileExplorer = TryCast(_pageContainsRadFileExplorer.FindControl("RadFileExplorer1"), RadFileExplorer)
        Dim dirCount As Integer = orgDir2.Directories.Length
        Dim pageSize As Integer = fileExplorer.FileList.PageSize
        Dim index As Integer = dirCount
        For Each file As FileItem In orgDir.Files
            If index > startIndex + pageSize Then
                Exit For
            End If
            If startIndex < dirCount AndAlso index < dirCount Then
                index = dirCount
            End If
            'A little visible change to the files
            file.Name = index.ToString() + "_" + file.Name
            'A custom file-change logic could be implemented here
            index += 1
        Return orgDir
    End Function


    The subsequent number of every file is added to its name.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.