Apply changes to the files on the current page

Thread is closed for posting
1 posts, 0 answers
  1. 63F75A2C-1F16-4AED-AFE8-B1BBD57646AD
    63F75A2C-1F16-4AED-AFE8-B1BBD57646AD avatar
    1572 posts
    Member since:
    Oct 2004

    Posted 07 Nov 2012 Link to this post

    Requirements

    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


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

    PROJECT DESCRIPTION
    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:

    C#
    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"]);
    }

    VB
    If Not IsPostBack Then
        startIndex = 0
    Else
        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:

    C#
    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
     
            index++;
        }
        return orgDir;
    }

    VB
    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
        Next
        Return orgDir
    End Function

    THE RESULT

    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.