dotnet-Snippets.com
Snippets: 61 | Registered User: 61 | Visitors online: 4
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Compare Files

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 5375

Description:

This method compare 2 files and returns true or false.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
private bool CompareFiles(string File1, string File2)
{
	FileInfo FI1 = new FileInfo(File1);
	FileInfo FI2 = new FileInfo(File2);

	if (FI1.Length != FI2.Length)
		return false;

	byte[] bytesFile1 = File.ReadAllBytes(File1);
	byte[] bytesFile2 = File.ReadAllBytes(File2);

	if (bytesFile1.Length != bytesFile2.Length)
		return false;

	for (int i = 0; i <= bytesFile2.Length - 1; i++)
	{
		if (bytesFile1[i] != bytesFile2[i])
			return false;
	}
	return true;
}


Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)