Sort Items by Name and Date

4 posts, 2 answers
  1. Robert
    Robert  avatar
    68 posts
    Member since:
    Feb 2009

    Posted 19 Mar 2012 Link to this post

    I'm working with the RadFileExplorer, and the ViewPath is configured in the C#;

    My goal is to sort the items in the RadFileExplorer by name and date, such as

    CD 3-1

    CD 3-2

    CD 3-14

    CD 3-18

    CD 3-24

    Rather than the default behavior of

     

    CD 3-1

    CD 3-14

    CD 3-18

    CD 3-2

    CD 3-24

    using (SqlConnection connection = new SqlConnection(newConnect))
                            {
                                // Create the Command and Parameter objects;
                                SqlCommand command = new SqlCommand(queryString, connection);
      
                                // Open the connection in a try/catch block; 
                                // Create and execute the DataReader; 
                                try
                                {
                                    connection.Open();
                                    SqlDataReader reader = command.ExecuteReader();
                                      
                                    while (reader.Read())
                                    {                                   
                                        UsernameDB = (reader[1]).ToString();
      
                                        listViewPaths.Add(reader.GetString(3));
                                        listUploadDeletePaths.Add(reader.GetString(4));
      
                                        WebPageTitle = (reader[5]).ToString();
                                    }
                                    reader.Close();
                                }
                                catch (Exception ex)
                                {
      
                                }
                            }
      
     RadFileExplorer1.Configuration.ViewPaths = listViewPaths.ToArray();

     

  2. Answer
    Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 20 Mar 2012 Link to this post

    Hello Robert,

    If I understand your scenario correctly, the listed folders are set as a separate items to the ViewPaths property of RadFileExplorer. If this is the case, the folders passed to the ViewPaths property are displayed in the same order that they appear in the array. So, in order to achieve the required result you need to manually sort the list before passing it to the ViewPaths property.

    If you need to apply custom ordering to all the files and folders listed in RadFileExplorer you need to subclass FileSystemContentProvider and override its ResolveRootDirectoryAsTree()  and ResolveDirecotory() methods to apply the order of the displayed items. The folders are listed by the ResolveRootDirectoryAsTree() method and the files are listed by ResolveDirectory() method. For example, if you want to apply custom ordering to the files only you need to override the ResolveDirectory() method and apply the custom ordering to the Files property of the DirectoryItem before returning it:
    public override DirectoryItem ResolveDirectory(string path)
    {
        DirectoryItem orgDir = base.ResolveDirectory(path);
        orgDir.Files.OrderBy(f => f.Name);
     
        return orgDir;
    }

    Additional information regarding the usage of content provider is available in the following help article:
    Using custom FileBrowserContentProvider

    Greetings,
    Dobromir
    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
  4. Robert
    Robert  avatar
    68 posts
    Member since:
    Feb 2009

    Posted 20 Mar 2012 Link to this post

    Thanks for the additional details;

    By any chance, is there a sample Visual Studio 2010 solution available for download?

    On the FTP Server where documents are stored, the various .pdf and .xls documents are arranged by name and date;

    However, perhaps because only the top-level folder (~/Documents) is specified when applied to

    RadFileExplorer1.Configuration.ViewPath, the documents are not arranged in date order;

    Example of RadFileExplorer display of documents on website:

    CD 3-16-12.pdf
    CD 3-16-12.xls
    CD 3-2-12.pdf
    CD 3-2-12.xls
    CD 3-5-12.pdf
    CD 3-5-12.xls


  5. Answer
    Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 22 Mar 2012 Link to this post

    Hi Robert,

    We do not have such example prepared, but please note that the implementation of custom sorting / ordering of a list / array is a general programming knowledge. In the following MSDN article you can find an example of custom ordering:
    http://msdn.microsoft.com/en-us/library/bb549422.aspx

    Regards,
    Dobromir
    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.
Back to Top