Sorting a UnifiedDirectory

Vote:
 

Hi!

I have a method that lists all directories in a given folder... using foreach:

foreach (UnifiedDirectory subDirectory in directory.Directories)
            {
                if (subDirectory.QueryDistinctAccess(AccessLevel.Read))
                {
                    writer.WriteLine("");

                    writer.Write(
                        DirectoryFormat,
                        HttpUtility.HtmlEncode(subDirectory.Name));

                    ListDirectories(subDirectory, writer);

                    writer.WriteLine("");
                }
            }

    

I would like to be able to reverse the order (they are now automatically listed in alphabetic order - the way they are ordered in the filemanager)... Is this possible in some kind of easy way to reverse the order (descending - with a UnifiedDirectory)?

#76579
Oct 29, 2013 9:46
Vote:
 

Not sure, but maybe you could use Linq and first Cast the Directories and the just do a Reverse?

directory.Directories.Cast<EPiServer.Web.Hosting.UnifiedDirectory>().Reverse()

#76588
Oct 29, 2013 11:56
Vote:
 

Great! It works perfectly... Many thanks!

#76598
Oct 29, 2013 12:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.