3 Replies - 1528 Views - Last Post: 23 February 2010 - 01:24 PM Rate Topic: -----

#1 andrey_cool  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 08-February 10

How can i check a file's md5 if it's equal to one in a listbox

Posted 22 February 2010 - 09:25 AM

How can i check a file's md5 if it's equal to one in a listbox? Like this

If file.MD5 = listbox1.Items.Contains(File.Md5) then
MessageBox.Show("The file is the same")
else
messagebox.Show("The file is changed")
end if

plz help :( :cry2:

Is This A Good Question/Topic? 0
  • +

Replies To: How can i check a file's md5 if it's equal to one in a listbox

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: How can i check a file's md5 if it's equal to one in a listbox

Posted 22 February 2010 - 05:48 PM

Here's a snippet, written in C#, to compute a file's MD5 checksum:

Calculate MD5 Checksum for a File
Was This Post Helpful? 0
  • +
  • -

#3 iBot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-February 10

Re: How can i check a file's md5 if it's equal to one in a listbox

Posted 22 February 2010 - 10:29 PM

Can't remember where I got it but just found it on my comp.


Usage:

CompareFiles(Path to first file,Path to second file)



Imports:

Imports System.IO
Imports System.Security.Cryptography


Snippet:

    Public Function CompareFiles(ByVal FirstFile As String, _
           ByVal SecondFile As String) As Boolean
        Return ReadFile(FirstFile) = ReadFile(SecondFile)
    End Function

    Private Function ReadFile(ByVal Path As String) As String
        Dim ReadFileStream As FileStream
        Dim FileEncoding As New System.Text.ASCIIEncoding()
        Dim FileReader As StreamReader
        Dim HashData As New MD5CryptoServiceProvider()
        ReadFileStream = New FileStream(Path, FileMode.Open)
        FileReader = New StreamReader(ReadFileStream)
        Dim FileBytes = FileEncoding.GetBytes(FileReader.ReadToEnd)
        Dim FetchedContent = FileEncoding.GetString(HashData.ComputeHash(FileBytes))
        FileReader.Close()
        ReadFileStream.Close()
        Return FetchedContent
    End Function

This post has been edited by iBot: 22 February 2010 - 10:31 PM

Was This Post Helpful? 0
  • +
  • -

#4 andrey_cool  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 08-February 10

Re: How can i check a file's md5 if it's equal to one in a listbox

Posted 23 February 2010 - 01:24 PM

View PostiBot, on 22 February 2010 - 09:29 PM, said:

Can't remember where I got it but just found it on my comp.


Usage:

CompareFiles(Path to first file,Path to second file)



Imports:

Imports System.IO
Imports System.Security.Cryptography


Snippet:

    Public Function CompareFiles(ByVal FirstFile As String, _
           ByVal SecondFile As String) As Boolean
        Return ReadFile(FirstFile) = ReadFile(SecondFile)
    End Function

    Private Function ReadFile(ByVal Path As String) As String
        Dim ReadFileStream As FileStream
        Dim FileEncoding As New System.Text.ASCIIEncoding()
        Dim FileReader As StreamReader
        Dim HashData As New MD5CryptoServiceProvider()
        ReadFileStream = New FileStream(Path, FileMode.Open)
        FileReader = New StreamReader(ReadFileStream)
        Dim FileBytes = FileEncoding.GetBytes(FileReader.ReadToEnd)
        Dim FetchedContent = FileEncoding.GetString(HashData.ComputeHash(FileBytes))
        FileReader.Close()
        ReadFileStream.Close()
        Return FetchedContent
    End Function


thanks it works fine! cheers!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1