I manage a website that pulls data in from an XML file, the file is updated every night around midnight. I am trying to write a simple piece of code that says on the website, File Last Updated: something something. After poking around and trying several different solutions, (I tried several variations using FileInfo to no avail) I decided to post here.
I tried Both GetCreationTime and GetLastWriteTime with FileInfo but I keep getting back 12/30/1600 or something similar no where near the correct date. When the file gets uploaded it just overwrites the old one so I wasn’t sure which method to use either.
Current Filinfo Code:
FileInfo fileInfo = new FileInfo("feed/VEHICLES.XML");
DateTime timeOfCreation = fileInfo.CreationTime;
modifieddate.Text = timeOfCreation.ToString();
this returns 12/31/1600 7:00:00 PM but it should be 11/14/2011 1:41 AM
You’re using a relative path without knowing what the current directory is.
You probably want
Server.MapPath("~/feed/VEHICLES.XML").If the file isn’t in your application directory, you’ll need to find its absolute path.