Is there away to check an xml file on a website to see if it has changed siince last check?
Printable View
Is there away to check an xml file on a website to see if it has changed siince last check?
Please post unrelated questions in separate threads. One thread per topic and one topic per thread.
With regards to the first question, do you have FTP access to the server? I'm not sure it would be possible using HTTP other than by downloading and testing the contents, but if you can use FTP then you can get the file date.
Yes, I do have access to FTP.
Can you explain how to download the file onto the local machine and to check for updates that way?
I would suggest that you use an FtpWebRequest with the Method set to GetDateTimeStamp. You can then compare that to the value for the last file you retrieved.
If you really do want to download the file first then you can use WebClient.DownloadFile. In order to compare the file to see if its contents have changed I would suggest that you create an MD5 hash. If it's different to the value for the last file then the contents have changed. Given that you need to create a Byte array from the file to create the hash, you might want to call DownloadData instead of DownloadFile. DownloadData returns a Byte array directly, so if the data hasn't changed you wouldn't bother saving a file at all.
Could you point me in some code examples? Also doing a datetimestamp wouldn't work since the file is automatically created and updated with new/changed info.
That page is dynamic and it updates every 2-5 min and updates with the latest information.
Then the MD5 hash is probably the best way to go. You should get the downloading bit working first, then worry about the hashing. You can either use WebClient.DownloadFile and then File.ReadAllBytes to get a Byte array or else use WebClient.DownloadData to get a Byte array and then File.WriteAllBytes to create a file. I'd go with the second option as there's no point creating a file if the data hasn't changed.
That said, if the file is very large then reading it all into a Byte array at the same time might not be practical, so DownloadFile and then reading the data in chunks would be a better option.
Once you've got the download happening, you can then look at the MD5CryptoServiceProvider class to create the hash.
It going to be a small xml. I will take a look at this and see what I can come up with.
Okay, I got another ideal... On First Update then save the main line to the user preferences and then each additional update to check and see if the lines are the same if not then to resave and display that data.
Now I'm not sure how to go about that?
Thanks for the help, I got it worked out with the last option I posted.