how to read the date and time when the files are uploaded (plz plz help)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Adela Arpitha
    New Member
    • Jan 2008
    • 15

    how to read the date and time when the files are uploaded (plz plz help)

    Hi,
    i'm using asp.net 1.1 for my project. I have a written a c# code where the user can upload his files through the file upload component which gets uploaded to the specified path in a local disk and these files are viewed on the user screen application using the concept of fetching files from the local drive.
    I have taken a table to store these files in 1 column and in the other column i have given hyperlinks to download the files.
    I have actually tried to do newsletter archiving, but the files get displayed depending on the alphabetical order which i dont want. I want them to be listed in the latest upload pattern depending on the date and time which i am not able to code efficiently.
    Can anyone please please help me out with this.......plea se...
    Here is the code i have used.....

    using System.IO;

    namespace FileDownLoadExa mple
    {
    public class WebForm1 : System.Web.UI.P age
    {
    protected System.Web.UI.W ebControls.Tabl e Table1;
    private void Page_Load(objec t sender, System.EventArg s e)
    {
    if(Request.Quer yString["filename"]!= null)
    {
    DownLoadFile(Re quest.QueryStri ng"filename"]);
    }
    if(!IsPostBack)
    {
    LoadFileInfo();
    }
    }

    private void LoadFileInfo()
    {
    DirectoryInfo dir = new DirectoryInfo(" c:/uploads");
    FileInfo[] file_info_array = dir.GetFiles();

    foreach(FileInf o file_info in file_info_array )
    {
    TableRow row = new TableRow();
    TableCell cell1 = new TableCell();
    TableCell cell2 = new TableCell();

    cell1.Text = file_info.Name;
    HyperLink link = new HyperLink();
    link.Text = "Download";
    link.NavigateUr l ="./WebForm1.aspx?f ilename="+file_ info.Name;
    cell2.Controls. Add(link);
    row.Controls.Ad d(cell1);
    row.Controls.Ad d(cell2);
    Table1.Controls .Add(row);
    }

    }

    private void DownLoadFile(st ring filename)
    {
    try
    {
    Response.Clear( );
    string Filename = Request.QuerySt ring["filename"];
    string downloadPath = "c:/uploads/"+Filename;
    Response.Conten tType ="applicatio n/octet-stream";
    Response.AddHea der("Content-Disposition","a ttachment; filename="+File name);
    Response.Transm itFile(download Path);
    }
    catch(HttpExcep tion err)
    {
    Response.Write( err.ToString()) ;
    }
    }
  • kunal pawar
    Contributor
    • Oct 2007
    • 297

    #2
    There may be property for file like created date please it and store this in Datable along with file name, this helps to sort by date

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      When a file gets uploaded, simple keep track of the DateTime.Now instance?

      Comment

      Working...