【问题标题】:File Details on a Windows like folder pane类似 Windows 的文件夹窗格中的文件详细信息
【发布时间】:2012-11-22 12:54:54
【问题描述】:

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

FileName | Extension | UploadedDate | LastDownloadedDate

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

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

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

谢谢!

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您可以使用System.IO.FileInfo 类获取List,然后将其绑定到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();
    

    【讨论】:

      【解决方案2】:

      这个Link 可能会帮助你,但我不确定你是否可以在任何默认属性中获取任何上传/下载的信息。

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

      【讨论】:

        【解决方案3】:

        请查看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();
        

        【讨论】:

        • 这一次只给出一个文件。
        猜你喜欢
        • 1970-01-01
        • 2019-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-25
        • 2014-10-05
        • 1970-01-01
        • 2021-01-12
        相关资源
        最近更新 更多