Ok,
I got this fixed.
Thanks for all the help everybody.
I had to change around the checkduplicate function, added some closes and set=nothing
Here is the completed function
Private Function CheckDuplicate(ByVal PrimaryFile As String) As Integer
Returns 0 if no duplicates,
returns 1 if duplicate found
Dim filestr As String
Dim rtn As Integer = 0
Dim fs1 As FileStream
Dim fs2 As FileStream
Dim fs2Open As Integer = 0
fs1 = New FileStream(PrimaryFile, FileMode.Open, FileAccess.Read)
Dim Hash As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim PrimaryHashBytes As Byte() = Hash.ComputeHash(fs1)
Dim CompareHashBytes As Byte()
Try
If Directory.Exists(PhotosetPath) Then
For Each filestr In Directory.GetFiles(PhotosetPath)
Check if file ext are the same, if not skip compare
If GetExtension(filestr) = GetExtension(PrimaryFile) Then
fs2open = 1
Dim Hash2 As New System.Security.Cryptography.MD5CryptoServiceProvider
fs2 = New FileStream(filestr, FileMode.Open, FileAccess.Read)
CompareHashBytes = Hash2.ComputeHash(fs2) New FileStream(filestr, FileMode.Open, FileAccess.Read))
Try
If System.Text.ASCIIEncoding.ASCII.GetString(PrimaryHashBytes) = System.Text.ASCIIEncoding.ASCII.GetString(CompareHashBytes) Then
Duplicatefile1 = PrimaryFile
Duplicatefile2 = filestr
Duplicate = 0
frmIShowDuplicate.ShowDialog()
If Duplicate = 1 Then
rtn = 1
End If
End If
Catch
MessageBox.Show("Error ASCIIEncoding")
End Try
CompareHashBytes = Nothing
Hash2.Clear()
End If
Next
End If
Catch
MessageBox.Show("Error Directory does not Exist")
End Try
PrimaryHashBytes = Nothing
Hash.Clear()
fs1.Close()
If fs2Open = 1 Then
fs2.Close()
End If
Return rtn
End Function