directoryInfo.CreationTime

Qamar, Mo 106 Reputation points
2020-12-02T19:59:07.84+00:00

How do I get the directoryInfo.CreationTime and the Filename in the ListBox (FileList) with Item Text and the Value. I want to display the filename and need the date for something else.

    private void BindFileNamesToList()
    {
        string extension = "pdf";  
        string folderPath = Server.MapPath("~/Files/");
        FileInfo[] fileInfo = GetFilesFromFolder(folderPath, (extension == "") ? "pdf" : extension);

        FilesList.Items.Clear();

        foreach (FileInfo fileInfoTemp in fileInfo)
        {
            ListItem listItem = new ListItem(fileInfoTemp.Name, fileInfoTemp.Name);
            FilesList.Items.Add(listItem);
        }
    }

    FileInfo[] GetFilesFromFolder(string folderName, string extension)
    {
        DirectoryInfo directoryInfo = new DirectoryInfo(folderName);
        DateTime creationTime = directoryInfo.CreationTime;
        string internalExtension = string.Concat("*.", extension);
        FileInfo[] fileInfo = directoryInfo.GetFiles(internalExtension, SearchOption.AllDirectories);

        return fileInfo;
    }
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,500 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,994 questions
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.