directoryInfo.CreationTime
Qamar, Mo
106
Reputation points
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;
}
Sign in to answer