I am converting a code from c++ to c#. The code uses the function
findFirstFile() to return the first file of the directory..

Is this function present in c#, or there are any modifications to the
function..The function uses a header windows.h. What is its replacement in c#?

MSDN has no example for this function in c# ..
plz help.....

I don't know if this function exists, but you can always make your own like this:

Something like a dir-command in DOS

using System;
using System.IO;

class MyProg
{
    static void Main(string[] args) 
    {
        DirectoryInfo dir = new DirectoryInfo(@"c:\");
        FileInfo[] files = dir.GetFiles(); //return files of the c dir

        foreach (FileInfo file in files) //look for first file in files array
       {
            Console.Write("Name: " + file.Name + "  ");
            Console.WriteLine("Size: " + file.Length.ToString()); //etc.
        }
    }
}

This example will find the 1st file in a directory. Edit as necessary:

using System.IO;

string dirname = "images/"; //edit this line.
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath(dirname));
FileInfo[] pics = dirInfo.GetFiles("*.*"); //use *.jpg for jpg files only, etc.

int cont = 0;

foreach (FileInfo fi in pics)
{
    if (cont == 0)
    {
        label_firstfile.Text = fi.Name;
        cont++;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.