Finding LastModifiedDate of file using URL
There's a website that maintains links to PDF files, and I want to check to see if the file has changed since the last time I downloaded it. I've got everything working except retrieving the LastModifiedDate of the file. The code I am using is as follows:
Code:
Try
Dim req As HttpWebRequest = (WebRequest.Create(url))
Dim resp As HttpWebResponse = (req.GetResponse())
Dim dt As String = resp.LastModified.ToString()
lblLnk1Mthd2.Text = dt
Catch ex As Exception
lblLnk1Mthd2.Text = "Error"
End Try
I am using VS 2010 on Windows 7, and have verified that the url I pass in does exist and is a valid link to a PDF file. What happens when I run this code is that the current date/time is returned, instead of the last modified date of the PDF file. Does anybody have any suggestions on how I can get the LastModifiedDate of a PDF on the net? Thanks in advance.
Re: Finding LastModifiedDate of file using URL
You're doing it. This code works perfectly for files of all kinds on the test sites I used. So you're getting what the site gives you.
Re: Finding LastModifiedDate of file using URL
If I'm doing it right, why is it returning the current date/time every time I run the thing? The specific file I'm looking at is:
http://cignaforhcp.cigna.com/public/..._treatment.pdf
Re: Finding LastModifiedDate of file using URL
Because, as I said, that is what the site is giving you. It may that the file is essentially created for you at the time of access, or that the last modified date is hidden at the server, or any number of other reasons. The point is that there is nothing you can do about it. It is controlled entirely by the server and is therefore out of your hands.