Link to home
Start Free TrialLog in
Avatar of jcm4101
jcm4101Flag for Australia

asked on

How to hash (MD5 or SHA1) a file with VB.NET

Hi experts..
I have a VB.NET application which imports a few csv files into a database nightly..
I need to ascertain if the file has changed from the previous nights import before I decide to import it or not.

I thought the easiest way would be to hash the file and store this hash in a table.
Then, each subsequent nightly import, I would simply hash the file, compare it with the hash of the file uploaded the previous night, if the hash's match, do nothing, if the hash's are different, perform the import..

So, can anyone poiont me in the right direction for hashing a file with VB.NET please??

Thanks in advance.

D
ASKER CERTIFIED SOLUTION
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jcm4101

ASKER

Excellent work...
Thanks for the quick and complete solution.

D
Avatar of jcm4101

ASKER

Actually, I'm a bit confused...

What's the correct way to call this class??

Ta
Avatar of nffvrxqgrcfqvvc
nffvrxqgrcfqvvc

Whoops I forgot to show that part :(
It's basically just one shared method wrapped in class so it's similiar in respect to a module where you don't need to create an instance.
In the example below I used hashed the windows calculator on Windows 7: calc.exe MD5: 4884da7754823b44ccc2b2106f21146e
 

Debug.Print(FileChecksum.IntegrityCheck("c:\windows\system32\calc.exe"))

Open in new window

Avatar of jcm4101

ASKER

Thanks  a lot..

Just sussed it out myself too  :-)

Greatly appreciated.

D