Results 1 to 12 of 12

Thread: New to C#, File Check

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    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.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    Re: New to C#, File Check

    Quote Originally Posted by jmcilhinney View Post
    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..

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: New to C#, File Check

    Quote Originally Posted by branmh View Post
    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?
    Quote Originally Posted by branmh View Post
    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    Re: New to C#, File Check

    That page is dynamic and it updates every 2-5 min and updates with the latest information.

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    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.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    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?

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    28

    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
  •  



Click Here to Expand Forum to Full Width