Results 1 to 2 of 2

Thread: Help in Var Sorting

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Help in Var Sorting

    i am practising Linq samples from ..MSDN

    I struck with a thing.
    Am trying to get files from a directory.
    The file names in the folder are 1.rtf,2.rtf,3.rtf.....10.rtf...., 20.rtf...,, 30.rtf


    C# Code Code:
    1. try
    2.  {
    3.      var ofileLst = from n in Directory.GetFiles(@"C:\Users\is1828\Desktop\OCR Data")
    4.                        where Path.GetExtension(n).Equals(".rtf")
    5.                        select n;
    6.  
    7.      foreach (var fil in ofileLst)
    8.      {   }
    9.                
    10.  }
    11. catch (Exception e)
    12. { }

    i neeed to sort th ofileLst on the basis of filename.
    because when looping, 1.rtf.10.rtf,.... 20.rtf,..

    but i need to get file in the sorted way..
    Last edited by vijy; Jul 28th, 2011 at 07:08 AM.
    Visual Studio.net 2010
    If this post is useful, rate it


  2. #2

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Help in Var Sorting

    Code:
    var ofileLst = from n in Directory.GetFiles(@"C:\Users\is1828\Desktop\OCR Data") 
                                where Path.GetExtension(n).Equals(".rtf") 
                                orderby Path.GetFileNameWithoutExtension(n) ascending 
                                select n;
    this also not working...
    Visual Studio.net 2010
    If this post is useful, rate it


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width