2

i have a problem in my project to find the Last Modified date of a site..

is any code to find that in asp.net

thanks in advance..

Prabhakaran
  • 92
  • 2
  • 10
  • 1
    http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.lastwritetime.aspx `System.IO.File.GetLastWriteTime(Request.PhysicalPath).ToString();` – Tim Schmelter Feb 10 '12 at 12:54

2 Answers2

1

Check out this question

How can you mine the "Last Modified Date" for an ASP.NET page which is based on a Master Page?

the basic code you need is this

Dim strPath As String = Request.PhysicalPath
Label1.Text = "Modified: " + System.IO.File.GetLastWriteTime(strPath).ToString()
Community
  • 1
  • 1
munnster79
  • 578
  • 3
  • 16
  • Why not mentioning this at the first time in your question? So you want to know last modified time of a webpage that is not the current page? Do you want to let the user select from a list of available pages or let him enter the url in a TextBox? – Tim Schmelter Feb 10 '12 at 13:17
0

FileInfo.LastWriteTime should give you what you need:

System.IO.File.GetLastWriteTime(Request.PhysicalPath).ToString();

According to your comment on the other answer, you instead want to get the last modified time of any web-site (not your own ASP.NET page). You could use Net.HttpWebRequest to request a given URL to get the LastModified property of the HttpResponse:

Protected Sub GetLastModifiedTimeOfWebPage(sender As Object, e As EventArgs)
    Dim url = Me.TxtURL.Text.Trim
    If Not url.StartsWith("http:") Then url = "http://" & url
    Dim ResponseStatus As System.Net.HttpStatusCode
    Dim lastModified As Date
    Try
        lastModified = RequestLastModified(url, ResponseStatus)
    Catch ex As System.Exception
        ' log and/or throw
        Throw
    End Try
    If ResponseStatus = Net.HttpStatusCode.OK Then
        Me.LblLastModified.Text = lastModified.ToString
    End If
End Sub

Public Shared Function RequestLastModified( _
    ByVal URL As String, _
    ByRef retStatus As Net.HttpStatusCode
) As Date
    Dim lastModified As Date = Date.MinValue
    Dim req As System.Net.HttpWebRequest
    Dim resp As System.Net.HttpWebResponse
    Try
        req = DirectCast(Net.HttpWebRequest.Create(New Uri(URL)), Net.HttpWebRequest)
        req.Method = "HEAD"
        resp = DirectCast(req.GetResponse(), Net.HttpWebResponse)
        retStatus = resp.StatusCode
        lastModified = resp.LastModified
    Catch ex As Exception
        Throw
    Finally
        If resp IsNot Nothing Then
            resp.Close()
        End If
    End Try

    Return lastModified
End Function

Note: Many sites lie with this property and return only the current time.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939