Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinct identifying hashcode for a file

Status
Not open for further replies.

Nebse

Programmer
May 7, 2002
18
DK
Does anybody have a code snippet that will generate a distinct number/code for a file. The code generated needs to be the same every time the routine is run on the same file - if the bytes of the file is changed the code needs to change to.

I need it for at project in which I need to determine if a set of files are the same version as an other set of identically named files...... kan anybody help me with this piece og hash code generating program code.

Nebse
 
I don't have time for a full sample, but basically:

1) Create a FileStream instance:
FileStream MyFS = new FileStream("c://Path", FileAccess.Read);

2) Create an instance of the default MD5 cryptographic hash object:
MD5 MyMD5 = MD5.Create();

3) Run the stream through the MD5 algorithm to produce a hash byte array:
byte TheHash[] = MyMD5.ComputeHash(MyFS);

Hope this gets you started.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top