How to take first file name from a folder in C#

Posted by riad on Stack Overflow See other posts from Stack Overflow or by riad
Published on 2010-05-26T11:24:34Z Indexed on 2010/05/26 11:31 UTC
Read the original article Hit count: 229

Filed under:

Hi all,

I need to get the first file name from a folder .How i do it in C#? My below code return all the file names.pls guide:

DirectoryInfo di = new DirectoryInfo(imgfolderPath);
foreach (FileInfo fi in di.GetFiles())
{
    if (fi.Name != "." && fi.Name != ".." && fi.Name != "Thumbs.db")
    {
        string fileName = fi.Name;
        string fullFileName = fileName.Substring(0, fileName.Length - 4);

         MessageBox.Show(fullFileName);
    }
}

I just need the first file name.pls guide

thanks Riad

© Stack Overflow or respective owner

Related posts about c#