|
-
Jul 4th, 2009, 09:52 AM
#1
Thread Starter
Junior Member
New to C#, File Check
Is there away to check an xml file on a website to see if it has changed siince last check?
Last edited by branmh; Jul 4th, 2009 at 11:46 AM.
-
Jul 4th, 2009, 10:50 AM
#2
Re: New to C#, File Check and Embedding Fonts
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.
-
Jul 4th, 2009, 11:45 AM
#3
Thread Starter
Junior Member
Re: New to C#, File Check and Embedding Fonts
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?
Last edited by branmh; Jul 4th, 2009 at 12:09 PM.
-
Jul 5th, 2009, 08:30 AM
#4
Re: New to C#, File Check
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.
-
Jul 5th, 2009, 08:43 AM
#5
Thread Starter
Junior Member
Re: New to C#, File Check
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.
-
Jul 5th, 2009, 08:53 AM
#6
Thread Starter
Junior Member
Re: New to C#, File Check
 Originally Posted by jmcilhinney
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.
Is there away with this method to check on line in file on the server first if different then to display the contents of the file..
-
Jul 5th, 2009, 08:54 AM
#7
Re: New to C#, File Check
 Originally Posted by branmh
Could you point me in some code examples?
I provided numerous type and member names. Have you looked them up in the documentation? have you searched for them on the web?
 Originally Posted by branmh
Also doing a datetimestamp wouldn't work since the file is automatically created and updated with new/changed info.
Are you saying that the date might change without the contents changing?
-
Jul 5th, 2009, 09:01 AM
#8
Thread Starter
Junior Member
Re: New to C#, File Check
That page is dynamic and it updates every 2-5 min and updates with the latest information.
-
Jul 5th, 2009, 09:09 AM
#9
Re: New to C#, File Check
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.
-
Jul 5th, 2009, 09:16 AM
#10
Thread Starter
Junior Member
Re: New to C#, File Check
It going to be a small xml. I will take a look at this and see what I can come up with.
-
Jul 5th, 2009, 10:08 AM
#11
Thread Starter
Junior Member
Re: New to C#, File Check
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?
-
Jul 5th, 2009, 12:19 PM
#12
Thread Starter
Junior Member
Re: New to C#, File Check
Thanks for the help, I got it worked out with the last option I posted.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|