get file attributes present in a folder c#

This partial code retrieves file names. I need help with the following remaining:

1. Date file created
2. Date file last modified
3. Number of rows in Sheet1

I appreciate the help.

        ExcelFiles xlFile = new ExcelFiles();

        // Put file names in the directory into array.
        string dirPath ="C:\\Users\\Mike\\Data\\"; 
        var files = Directory
                        .EnumerateFiles(dirPath, "*", SearchOption.TopDirectoryOnly)
                        .Select(Path.GetFileName);

        // store file names in xlFile object
        foreach (string name in files)
        {
            string file =name;
            string fileExtention = name.Substring(name.Length - 5);
            if (fileExtention == ".xlsx")
            {
                xlFile.filename = file;

                // add the following file attribute to xlFile object 
                //xlFile.recourdCount =  // number of rows in Sheet1
                //xlFile.createdOn =  // date file created
                //xlFile.lastModified =// date file last modified
            }
        }

Open in new window

LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
1 and 2 can be obtained from FileInfo as shown below:
FileInfo info = new FileInfo(name);
xlFile.createdOn = info.CreationTime;  //assusming that  xlFile.createdOn is DateTime type.  
xlFile.lastModified = info.LastWriteTime;  //assusming that  xlFile.createdOn is DateTime type.

Open in new window


For 3 you can use GetNumberOfRows (uses ODBC) as shown in Sid Holland answer:
xlFile.recourdCount = GetNumberOfRows(name, "Sheet1") ;

Open in new window

Note: I do not recommend using Excel Interop code, because it is not thread-safe.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.