locked
Order month

    Question

  • Hello 

    I want to order a list of month in desc order dec nov .. ;but i when i run this code i have the order by  alphabet how cani solve this

     private void loadGrid()
            {
                List<FileArchive> fiList = new List<FileArchive>() ;
                String path = Request.QueryString["Path"];
                DirectoryInfo info = new DirectoryInfo(path);
                FileInfo[] files = info.GetFiles().OrderByDescending(m => m.CreationTime).ToArray();
                foreach (FileInfo fi in files)
                {
                    FileArchive FA = new FileArchive();
                    FA.Name = fi.Name;
                    FA.FullName = fi.FullName;
                    FA.CreationDate = fi.CreationTime;
                    FA.RegroupingField =//fi.CreationTime.ToString("MM") + "-" + 
                    fi.CreationTime.ToString("MMMM") + " | " + fi.CreationTime.Year;
                 
                    fiList.Add(FA);
               
                    
                }

    Tuesday, September 30, 2014 11:32 AM

Answers

  • Hi AhmedWP,

    Will this help?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 08, 2014 9:14 AM
    Moderator

All replies

  • I assume that OrderByDescending applies a ToString to m.CreationTime. I've seen some similar issues being mentioned doing a Search right now but nevere really seen a clean answer to it. One approach to solve this might be to do a "ToString" yourself that gives you a string that sorts correctly, e.g.:

    FileInfo[] files = info.GetFiles().OrderByDescending(m => m.CreationTime.ToString("yyyyMMdd")).ToArray();

    Tuesday, September 30, 2014 11:48 AM
  • the order always with alphabet nothing change
    Tuesday, September 30, 2014 1:49 PM
  • Hi AhmedWP,

    Will this help?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, October 08, 2014 9:14 AM
    Moderator