locked
How to get The Modified date of image ?? RRS feed

  • Question

  • Hello All,

                    I am trying to get the Modified  date of a  image using c# like in Mozilla FireFox. I getting some other property's but not getting this  is Any option to get this .

    with regards ,

    jophy .


    • Edited by JophyJob Wednesday, January 16, 2013 6:23 AM
    • Moved by Sheldon _Xiao Thursday, January 17, 2013 7:52 AM
    Wednesday, January 16, 2013 6:21 AM

Answers

  • If the image has the meta data for the date it was taken then it will be there.  In this case it is not.  This will also be the case for many images on the web, people like their privacy and images are often automatically filtered. 

    If you want the image metadata then get it from a locally cached copy.....formats are exif, iptc and ??

    If the meta data is not available the only other date you have to go on is the file last modified date.  The example you provided uses the last modified date.

    This code works.  used .net 4 but should work for 2.0 as well:

                Uri myUri = new Uri("http://www.hightechtalks.com/csharp-code-export/images/start-1.png");
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); 
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    Console.WriteLine("last-modified: " ,myHttpWebResponse.LastModified);
                }
                myHttpWebResponse.Close(); 

    The libraries:

    using System.Net;

    cs




    • Proposed as answer by Patrice ScribeMVP Thursday, January 17, 2013 10:36 AM
    • Edited by CountryStyle Thursday, January 17, 2013 11:10 AM
    • Marked as answer by JophyJob Wednesday, January 30, 2013 5:52 AM
    Thursday, January 17, 2013 10:31 AM

All replies

  • Try using BitmapMetadata. See the SO answer here for an example of how to use it.
    Wednesday, January 16, 2013 8:00 AM
  • Hello Chase,

                          It not help me  , it Not working . BitmapMetadata Only have DateTaken and other , no option to get Modified date . System.Drawing.Imaging also not not working .

    Wednesday, January 16, 2013 8:58 AM
  • My bad. You can get the modified using FileInfo.LastWriteTime

    FileInfo fi = new FileInfo(@"c:\test.jpg");
    
    Debug.WriteLine(fi.LastWriteTime);

    (FileInfo is under the System.IO namespace)

    Wednesday, January 16, 2013 9:35 AM
  •        But The image is in the web , so the FileInfo Not work . When we download the file , all property's set to download time . I also try that Not working .
    Wednesday, January 16, 2013 9:41 AM
  • I think the date modified image info you get from FireFox is for the copy of the image cached on the local computer. So the date will just be the last time it was downloaded.
    Wednesday, January 16, 2013 9:55 AM
  • Hello Chase ,

                           It is Not possible .. Because i bye the PC in 2012 ..   

    Wednesday, January 16, 2013 9:58 AM
  • Hello All ,

                  I got a Link that say about the web page modification Date ,  When try that it is almost the same (when page is static ) . I see one Microsoft link http://msdn.microsoft.com/en-us/library/system.net.httpwebresponse.lastmodified.aspx , it also use this method . Is any other option to Get Modified Date of image that placed on server .

    with regards ,

    jophy .

    Thursday, January 17, 2013 8:10 AM
  • Be aware that "an image" as file type does not exist. 

    There are many image types like png, bpm, gif so tell first about what kind of images you are talking. 

    If you then search for a certain type like jpg, you will find plenty of solutions.


    Success
    Cor

    Thursday, January 17, 2013 9:09 AM
  • Hi JophyJob,

      The introducation of this property only said that it gets the last date and time that the contents of the response were modified.So the image inside your web page doesn't equal to  the last data and time of your web page.I feel  J Chase's lastest reply has menthioned its implementation,you can use the cache inside your machine,the content of its storage has your wanted image,you only need to get the EXIF of this image.

      Sincerely,

      Jason Wang

               


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, January 17, 2013 9:12 AM
  • Hello Cor Lighert,

                             I am working on jpg type of images ..

    Thursday, January 17, 2013 9:18 AM
  • Hello Jason ,

                         But i see no information about the  Modified date in the EXIF properties  . it only have the Date of taken etc ... see the link  http://msdn.microsoft.com/en-us/library/system.drawing.imaging.propertyitem.id.aspx 

    Thursday, January 17, 2013 9:22 AM
  • If the image has the meta data for the date it was taken then it will be there.  In this case it is not.  This will also be the case for many images on the web, people like their privacy and images are often automatically filtered. 

    If you want the image metadata then get it from a locally cached copy.....formats are exif, iptc and ??

    If the meta data is not available the only other date you have to go on is the file last modified date.  The example you provided uses the last modified date.

    This code works.  used .net 4 but should work for 2.0 as well:

                Uri myUri = new Uri("http://www.hightechtalks.com/csharp-code-export/images/start-1.png");
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri); 
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                if (myHttpWebResponse.StatusCode == HttpStatusCode.OK)
                {
                    Console.WriteLine("last-modified: " ,myHttpWebResponse.LastModified);
                }
                myHttpWebResponse.Close(); 

    The libraries:

    using System.Net;

    cs




    • Proposed as answer by Patrice ScribeMVP Thursday, January 17, 2013 10:36 AM
    • Edited by CountryStyle Thursday, January 17, 2013 11:10 AM
    • Marked as answer by JophyJob Wednesday, January 30, 2013 5:52 AM
    Thursday, January 17, 2013 10:31 AM
  • Hello , 

             Sorry for the late replay . Is it work for Dynamic Web pages , we cannot get the correct  date ...

    We only get the today's date in that .   

    Tuesday, January 22, 2013 3:26 PM
  • you did not provide an example...but I don't think it matters because you will find that in some cases that the metadata is just not there.

    I guess you can start collecting all the images on the web and then try to match your image up to one in your database and then picking the earliest date.....somehow I don't think you have the funding for that :) and I dont' think there is a service out there like that, yet (look at TinEye)

    See my post from Thursday, January 17, 2013 10:31 AM




    Tuesday, January 22, 2013 4:43 PM
  • Seems expected for a dynamic page as the content is generated each time the page is hit (unless some caching is done server side) so the content IS brand new. If you are interested in images shown on this page you'll have to check specifically those images not the page that show them.

    Knowing what you are trying to do (not the technical description but just a plain English description of the ultimate goal) could also perhaps help to raise better suggestion.


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Thursday, January 24, 2013 12:00 PM
  • Jophy,

    Maybe a stupid question. But what do you mean with a modified image (jpg).

    A jpg image is a bitmap, what are you modifying in it. (As far as I know is every modifying in that format creating a new image).

    However, using the datetaken and the last file name you can probably see if it is a modification date or an original date.

    I found this page which describes it in C#

    http://nicholasarmstrong.com/2010/02/exif-quick-reference/


    Success
    Cor

    Thursday, January 24, 2013 4:17 PM