Last Modification Time of a Web Page

September 7th 2006 HTTP .NET Framework

The following code returns the time when a web resource was last modified:

static DateTime GetModificationTime(string url)  
{  
   WebRequest request = WebRequest.Create(url);  
   HttpWebResponse response = (HttpWebResponse) request.GetResponse();  
   DateTime lastModified = response.LastModified;  
   response.Close();  
   return lastModified;  
}

It's quite a simple piece of code actually and very similar to a sample in MSDN. But maybe it will be useful to someone since a member of my development team was convinced that there is just no way to get this information in .NET.

Get notified when a new blog post is published (usually every Friday):

Copyright
Creative Commons License