1

I need to show file details in a GridView for my web application. Also I need to list them in uploaded date order with most recent on top (descending order). For example I need the following details.

FileName | Extension | UploadedDate | LastDownloadedDate

I couldn't find any code on the web. Sorry, this could be easy but I only know how to get the files into a strying array. Here I get only filenames

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

How do I get the rest of the details?

Thanks !

3 Answers3

0

You can use System.IO.FileInfo class to get a List and then bind it to the 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();
Kaf
  • 33,101
  • 7
  • 58
  • 78
0

Please look to the System.IO namespace:

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();
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
Piotr Czarnecki
  • 1,688
  • 3
  • 14
  • 22
0

This Link might help you, but i am not sure if you can get any uploaded / downloaded information in any default propreties.

You can set some custom / extended properties to save those information and read the same when displaying on grid. Read and writing extended property depends on the file extension.

Community
  • 1
  • 1
Jsinh
  • 2,539
  • 1
  • 19
  • 35