Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Last Modified date of an External webpage

Last Modified date of an External webpage

Scheduled Pinned Locked Moved C#
helpcsharpjavaphphtml
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Patricker
    wrote on last edited by
    #1

    I am trying to retrieve the last modified date of an external webpage. I have found numerous ways to do this in vb, java, etc... but not in C#. Heres some of them: VB - http://www.freevbcode.com/ShowCode.asp?ID=362 ASP (so basically the same thing) - http://www.webdeveloper.com/forum/archive/index.php/t-3706.html I've tried using HTTPWebRequest and HTTPWebResponse, since HTTPWebResposne has a LastModified property, but this is when the response was last modified, not the page. So I'm stuck... Any help would be awesome :) --Peter

    R 1 Reply Last reply
    0
    • P Patricker

      I am trying to retrieve the last modified date of an external webpage. I have found numerous ways to do this in vb, java, etc... but not in C#. Heres some of them: VB - http://www.freevbcode.com/ShowCode.asp?ID=362 ASP (so basically the same thing) - http://www.webdeveloper.com/forum/archive/index.php/t-3706.html I've tried using HTTPWebRequest and HTTPWebResponse, since HTTPWebResposne has a LastModified property, but this is when the response was last modified, not the page. So I'm stuck... Any help would be awesome :) --Peter

      R Offline
      R Offline
      Rei Miyasaka
      wrote on last edited by
      #2

      You can call Response.GetResponseHeader("Last-Modified") to get the time, but then you have to parse it -- and there's about 3 standard time formats in HTTP. Luckily I wrote a parser for a web server[^] a while ago, so here it is:

      static DateTime ParseHttpTime(string str)
      {
      DateTime dt;
      try
      {
      dt = DateTime.ParseExact(str, httpDateTimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo,
      System.Globalization.DateTimeStyles.AllowWhiteSpaces | System.Globalization.DateTimeStyles.AdjustToUniversal);
      }
      catch(FormatException)
      {
      dt = DateTime.Parse(str, CultureInfo.InvariantCulture);
      }
      return dt;
      }

      The method can throw an ArgumentNullException if the input is null and a FormatException if the input isn't formatted properly. Keep in mind this happens a lot... most servers don't seem to return a Last-Modified value these days.

      P 1 Reply Last reply
      0
      • R Rei Miyasaka

        You can call Response.GetResponseHeader("Last-Modified") to get the time, but then you have to parse it -- and there's about 3 standard time formats in HTTP. Luckily I wrote a parser for a web server[^] a while ago, so here it is:

        static DateTime ParseHttpTime(string str)
        {
        DateTime dt;
        try
        {
        dt = DateTime.ParseExact(str, httpDateTimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo,
        System.Globalization.DateTimeStyles.AllowWhiteSpaces | System.Globalization.DateTimeStyles.AdjustToUniversal);
        }
        catch(FormatException)
        {
        dt = DateTime.Parse(str, CultureInfo.InvariantCulture);
        }
        return dt;
        }

        The method can throw an ArgumentNullException if the input is null and a FormatException if the input isn't formatted properly. Keep in mind this happens a lot... most servers don't seem to return a Last-Modified value these days.

        P Offline
        P Offline
        Patricker
        wrote on last edited by
        #3

        So if the server doesen't return a Last-Modified value, as you said most servers don't these days, then is it still possible to retrieve the Last-Modified date of a page via some other means? Or am i just out of luck? --Peter

        R 1 Reply Last reply
        0
        • P Patricker

          So if the server doesen't return a Last-Modified value, as you said most servers don't these days, then is it still possible to retrieve the Last-Modified date of a page via some other means? Or am i just out of luck? --Peter

          R Offline
          R Offline
          Rei Miyasaka
          wrote on last edited by
          #4

          I can't think of any other ways... :(

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups