How to ensure that a file has been received completely before reading it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Charles Cain
    New Member
    • Jul 2008
    • 3

    How to ensure that a file has been received completely before reading it?

    How can i ensure that i have received a file completely from an external source before reading it?Suppose i am receiving a file from an external source and i try to read the file before i have recieved the entire file.How can i ensure that this does not happen?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    This question was about to get lost in the .NET Articles section, so I saved it from
    drowning ;-)

    kind regards,

    Jos (moderator)

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Check the size of the file in bytes and make sure they are all there first?

      Comment

      • developing
        New Member
        • Mar 2007
        • 110

        #4
        where are you getting it from?

        depending on the download source, it might supply a checksum.
        if you control the download source, then supply a checksum before you begin the file download (md5 for sha1)

        then when the download has been inactive for 5 seconds, check the file against the checksum. If it matches, download is complete.

        If it doesn't, then either the file is corrupted or download isn't complete yet

        Comment

        • Charles Cain
          New Member
          • Jul 2008
          • 3

          #5
          I guess i need to explain the situation a bit more.[:)]

          I have this windows service running that polls certain folders for text and xml files received from an external source.Now the service should process only those files that have been received completely.Curr ently what is happening is that, whenever a huge file comes in the service tries to process it before it has been received completely.Ther e's no way to know the size or the contents of the file beforehand.Is there any way in which i can check if the file has been received completely?

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Hmm, you *might* be able to get away with trying to open the file for full read/write access, and saying don't share ANY access.
            My theory is that if the file is not finished "arriving", then something will still have a handle open to it. So your request for full rights with no sharing would fail if something else has it open?

            You could also poll for modified times and see when it's stopped changing for more then X amount of time?

            Comment

            • developing
              New Member
              • Mar 2007
              • 110

              #7
              how do you read the file? like after every hour or so....or is it event driven?

              Comment

              Working...