Click here to Skip to main content
15,891,744 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
ASP.NET
<asp:FileUpload ID="FileUpload1" runat="server" />
 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

C#
 // this is a aspx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class we : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        
       DateTime creationTime = File.GetCreationTime(FileUpload1.FileName);
        
        Label1.Text =creationTime.ToString() ; 
    }
}

I tried this ..but I got the output 01-01-1601 05:30:00 for all files. So what should I do?
Posted
Updated 26-May-20 20:33pm
v2

 
Share this answer
 
Comments
karan 2012 30-Apr-12 1:14am    
this is not my requriment ...this is not working
You could try with the 'FileInfo' class of the System.IO namespace.
The System.IO.FileInfo class has the CreationTime property that might help you.
 
Share this answer
 
Comments
karan 2012 30-Apr-12 1:14am    
i tried also wid fileinfo,,,but i got same answer ..so now what should i do?
FILETIME zero is 00:00 1 January 1601 which adjusted to your local time becomes 05:30.

The documentation says
If the file described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.

You should check if FileUpload1.FileName contains the path you expect it to and that the file is actually there.

Alan.
 
Share this answer
 
Comments
karan 2012 30-Apr-12 1:13am    
acctually..i dont save my file in server..
i just want to know the creation time of any file... that is store in different drive in computer..?
so what shoul i do?
saransat 13-Dec-13 2:22am    
Have u got solution for this problem..
saransat 13-Dec-13 2:22am    
Have u got solution for this problem..
Alan N 30-Apr-12 4:25am    
Did you check the FileName? The documentation for FileUpload.FileName says it just a filename and not the full path. It is highly likely that the GetCreationTime method does not find the file unless it has the full path.
Using File.GetLastWriteTime(@"C:\..\x.txt") for getting Last Saved Time is better;

If File.GetCreationTime is used on file that is copied to new location we get file copied time, copied to that Folder, in-spite of actual File creation datetime.
 
Share this answer
 
Comments
Richard Deeming 25-Oct-19 11:59am    
The only correct solution to this ancient question would be, "You can't".

Files uploaded to a website only send the name and the contents of the file. They don't send any other details, including the creation time, the last write time, or anything else.
Use
DateTime creationTime = File.GetCreationTime(FileUpload1.PostedFile.FileName);
 
Share this answer
 
Comments
Richard Deeming 27-May-20 13:33pm    
Once again, the only correct solution to this ancient question is "you can't".

Files uploaded to a website only send the name and the contents of the file. They don't send any other details, including the creation time, the last write time, or anything else.

Copying the code that was already in the question and posting it as a "solution" isn't going to make it suddenly start working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900