Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 635605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:25:22+00:00 2026-05-13T20:25:22+00:00

say i have a file A.doc. then i copy it to b.doc and move

  • 0

say i have a file A.doc.
then i copy it to b.doc and move it to another directory.
for me, it is still the same file.
but how can i determine that it is?
when i download files i sometimes read about getting the mda5 something or the checksum, but i don’t know what that is about.

Is there a way to check whether these files are binary equal?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:25:22+00:00Added an answer on May 13, 2026 at 8:25 pm

    If you want to be 100% sure of the exact bytes in the file being the same, then opening two streams and comparing each byte of the files is the only way.

    If you just want to be pretty sure (99.9999%?), I would calculate a MD5 hash of each file and compare the hashes instead. Check out System.Security.Cryptography.MD5CryptoServiceProvider.

    In my testing, if the files are usually equivalent then comparing MD5 hashes is about three times faster than comparing each byte of the file.
    If the files are usually different then comparing byte-by-byte will be much faster, because you don’t have to read in the whole file, you can stop as soon as a single byte differs.

    Edit: I originally based this answer off a quick test which read from each file byte-by-byte, and compared them byte-by-byte. I falsely assumed that the buffered nature of the System.IO.FileStream would save me from worrying about hard disk block sizes and read speeds; this was not true. I retested my program that reads from each file in 4096 byte chunks and then compares the chunks – this method is slightly faster overall than MD5 even when the files are exactly the same, and will of course be much faster if they differ.

    I’m leaving this answer as a mild warning about the FileStream class, and because I still thinkit has some value as an answer to “how do I calculate the MD5 of a file in .NET”. Apart from that though, it’s not the best way to fulfill the original request.

    example of calculating the MD5 hashes of two files (now tested!):

    using (var reader1 = new System.IO.FileStream(filepath1, System.IO.FileMode.Open, System.IO.FileAccess.Read))
    {
        using (var reader2 = new System.IO.FileStream(filepath2, System.IO.FileMode.Open, System.IO.FileAccess.Read))
        {
            byte[] hash1;
            byte[] hash2;
    
            using (var md51 = new System.Security.Cryptography.MD5CryptoServiceProvider())
            {
                md51.ComputeHash(reader1);
                hash1 = md51.Hash;
            }
    
            using (var md52 = new System.Security.Cryptography.MD5CryptoServiceProvider())
            {
                md52.ComputeHash(reader2);
                hash2 = md52.Hash;
            }
    
            int j = 0;
            for (j = 0; j < hash1.Length; j++)
            {
                if (hash1[j] != hash2[j])
                {
                    break;
                }
            }
    
            if (j == hash1.Length)
            {
                Console.WriteLine("The files were equal.");
            }
            else
            {
                Console.WriteLine("The files were not equal.");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So say you have a file that is written in XML or soe other
Let's say I have a file that's Modified in master Modified in a feature
Say I have a data file that I want to process; I want to
I have an application (winforms) that downloads a file to user's temporary folder, then
Say I have file - a.csv ram,33,professional,doc shaym,23,salaried,eng Now I need this output (pls
I have a file say xyz.doc .I want to find the parent /Parents of
Let's say I have a filepath- Doc/Monday/File.txt I want to use a substr() to
Say I have file A, in middle of which have a tag string #INSERT_HERE#.
Say I have a file in my kohana 3 website called assets/somefile.jpg . I
Say I have a file with the format: key1/value1 key2/value2 key3/value3 .... Say I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.