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

Sort Items by Name and Date

3 Answers 81 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 19 Mar 2012, 03:58 PM
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();

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dobromir
Telerik team
answered on 20 Mar 2012, 03:15 PM
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.
0
Robert
Top achievements
Rank 1
answered on 20 Mar 2012, 05:47 PM
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


0
Accepted
Dobromir
Telerik team
answered on 22 Mar 2012, 12:50 PM
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.
Tags
FileExplorer
Asked by
Robert
Top achievements
Rank 1
Answers by
Dobromir
Telerik team
Robert
Top achievements
Rank 1
Share this question
or