Given a file on the local filesystem:
FileInfo file = new FileInfo(localFilename);
How can I get a CRC-value (or some kind of checksum) for that file?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Hash algorithms are generally better than CRCs because they have fewer collisions; modern hash algorithms are implemented as descendents of the
HashAlgorithmclass. MD5 and SHA1 are common choices.AFAIK, .NET does not include CRC classes, but I’ve written CRC32 and CRC16 classes that support all CRC-32 and CRC-16 algorithms.
To calculate the checksum (whether a hash algorithm or CRC), you’ll have to read in the entire file, chunk by chunk, passing the file data to the checksum algorithm. When you’re done with the entire file, retrieve the result from the checksum algorithm.