我有一个目录中的文件列表,我想按文件名对其进行排序。
这是主要代码:
var localPath = this.Server.MapPath("~/Content/Img/" + type + "/");
var directory = new DirectoryInfo(localPath);
isDirectory = directory.Exists;
if (isDirectory)
{
foreach (FileInfo f in directory.GetFiles())
{
Picture picture = new Picture();
picture.ImagePath = path;
picture.CreationDate = f.CreationTime;
picture.FileName = f.Name;
listPictures.Add(picture);
}
}
这是存储所有文件的类图片:
public class Picture
{
public string ImagePath { get; set; }
public string FileName { get; set; }
public DateTime CreationDate { get; set; }
}
你如何按文件名的顺序对文件列表进行排序?