tags:

views:

314

answers:

4

Is there a way to get the Last-Modified-Date of a file on a Web Site?

i.e. Here is an example file I have out there: http://www.ymcadetroit.org/atf/cf/%7B2101903E-A11A-4532-A64D-9D823368A605%7D/Birmingham_Youth_Sports_Parent_Manual.pdf

A: 

With just plain HTML, no you cannot.

You can with PHP, or ASP, or any other server side language.

Jon
+2  A: 

I believe the web server must be configured to send the last-modified date in an HTTP-header, this is certainly one way. Check out section 14.29 Last-Modified of this document:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Peter
+1  A: 

Here is some C# code to do it:

public DateTime GetLastModifyTime(string url)
{
        WebRequest request = WebRequest.Create(url);
        request.Credentials = CredentialCache.DefaultNetworkCredentials;
        request.Method = "HEAD";

        using (WebResponse response = request.GetResponse())
        {
            string lastModifyString = response.Headers.Get("Last-Modified");
            DateTime remoteTime;
            if (DateTime.TryParse(lastModifyString, out remoteTime))
            {
                return remoteTime;
            }

            return DateTime.MinValue;
        }
}
Eddie Deyo
+1  A: 

The HTTP intends the Last-Modified header field to declare the last modification date. But the server needs to know that date.

On static files whose content is sent directly to the client and not interpreted otherwise by the server (e.g. .html, .css, .js) it uses the last modified date of that file. But on files that generated content dynamically (PHP, Python, etc.) the script needs to specify that information itself. But unfortunatly many scripts don’t to that.

So if a Last-Modified header field is present, you can use that information. But if not, you cannot determin the last modification date.

Gumbo