473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

file check sum

Hi,

My app records some sound to a file and then copies it to a network drive.
We recently had some issues when file was copied corrupted besause of some network issues.
So i am going to make some copied file test against the original file to make sure it was copied correctly.

Are the any standard .NET remedies for that? Obviousely, comparing just size is not working sometimes,
and I also woudn't want to do a "by-byte" file comparing.

Any ideas would be highly appreciated!!!

Thank you,
Andrey
Nov 16 '05 #1
2 11072
MuZZy <le*******@yahoo.com> wrote:
My app records some sound to a file and then copies it to a network
drive. We recently had some issues when file was copied corrupted
besause of some network issues. So i am going to make some copied
file test against the original file to make sure it was copied
correctly.

Are the any standard .NET remedies for that? Obviousely, comparing
just size is not working sometimes, and I also woudn't want to do a
"by-byte" file comparing.

Any ideas would be highly appreciated!!!


You could use an MD5 hash, Crc32 or something similar to check the file
against.

As it happens, I have an Adler32 implementation you could use in my
MiscUtil library, if you want:
http://www.pobox.com/~skeet/csharp/miscutil

Using MD5 would probably be easier though, as you wouldn't need the
extra library. It would take more computation, but I wouldn't expect
that to be a problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
MuZZy <le*******@yahoo.com> wrote in
news:ut********************@rcn.net:
Hi,

My app records some sound to a file and then copies it to a
network drive. We recently had some issues when file was copied
corrupted besause of some network issues. So i am going to make
some copied file test against the original file to make sure it
was copied correctly.

Are the any standard .NET remedies for that? Obviousely,
comparing just size is not working sometimes, and I also woudn't
want to do a "by-byte" file comparing.


Andrey,

A good way to compare the physical contents of two files is to use a
checksum. Below is a method I use to calculate the MD5 checksum for
a given file:

using System.IO;
using System.Security.Cryptography;
using System.Text;

...

private static string GetMD5ChecksumForFile(string filename)
{
if (filename == null)
throw new ArgumentNullException("The 'filename' parameter cannot be null.");

if (!File.Exists(filename))
throw new ArgumentException(string.Format("Filename '{0}' does not exist.", filename));

using (FileStream fstream = new FileStream(filename, FileMode.Open))
{
byte[] hash = new MD5CryptoServiceProvider().ComputeHash(fstream);

// Convert the byte array to a printable string.
StringBuilder sb = new StringBuilder(32);
foreach (byte hex in hash)
sb.Append(hex.ToString("X2"));

return sb.ToString().ToUpper();
}
}
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
3
by: Don Pasquale | last post by:
The following function intends to delete "numberoflines" lines from a text file, named "s" (string pointer) and pointed to by file pointer "fp", starting from line "line". Now, the function...
2
by: mhadi | last post by:
Hello Please Help me!! The big bossman is screaming in my ear, I am only devloper of dotnet in my software house and know only to develop widows based application !! My boss wan't me to...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
1
by: John Wright | last post by:
During my program I load an exe file using reflection. My program loads the file using reflection, checks the assembly version and does an update if the network version is different from the local...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
3
by: sam_cit | last post by:
Hi Everyone, I have a buffer having some raw ASCII data and i want to write it into a file. One way is to loop through the buffer and write a single character at a time and close the file after...
24
by: Bill | last post by:
Hello, I'm trying to output buffer content to a file. I either get an access violation error, or crazy looking output in the file depending on which method I use to write the file. Can anyone...
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.