1

我需要在 GridView 中为我的 Web 应用程序显示文件详细信息。我还需要按上传日期顺序列出它们,最近的日期在最上面(降序)。例如,我需要以下详细信息。

FileName | Extension | UploadedDate | LastDownloadedDate

我在网上找不到任何代码。抱歉,这可能很容易,但我只知道如何将文件放入字符串数组中。在这里我只得到文件名

String[] files = Directory.GetFiles("myPath");

我如何获得其余的详细信息?

谢谢 !

4

3 回答 3

0

您可以使用System.IO.FileInfoclass 获取 aList然后将其绑定到GridView.

System.IO.FileInfo[] fInfo = new System.IO.DirectoryInfo("YOUR_PATH").GetFiles();

var filList = (from f in fInfo
           orderby f.CreationTime descending 
           select new
           {
             FileName = f.Name,
             UploadedDate = f.CreationTime,
             Extension = f.Extension,
             LastDownloadedDate = f.LastAccessTime //Not sure this would be the same.
           }).ToList();
于 2012-11-22T12:59:24.707 回答
0

请查看System.IO命名空间:

string extension = System.IO.Path.GetExtension(this.File1.PostedFile.FileName);
string path= Path.GetFileName(fileName);
string LastModified=System.IO.File.GetLastWriteTime(Server.MapPath("myFile.txt")).ToString();
于 2012-11-22T13:03:34.310 回答
0

链接可能会对您有所帮助,但我不确定您是否可以在任何默认属性中获取任何上传/下载的信息。

您可以设置一些自定义/扩展属性来保存这些信息并在网格上显示时读取它们。读写扩展属性取决于文件扩展名。

于 2012-11-22T13:04:45.557 回答