Jump to content
Gurzi

MD5 checksum , ficheiro não fecha.

Recommended Posts

Gurzi

Boas pessoal,

Estou a começar a brincar com ASP.NET e neste momento tenho em mãos um projecto que me obriga a fazer o checksum em md5 de dois ficheiros, caso sejam diferentes, aparece um butão para fazer file.copy com overwrite a true.

O que se passa é que estou a usar esta função para verificar o MD5 mas quando chego à parte do FILE.COPY ele diz que o ficheiro está a ser usado.

Está me a escapar alguma coisa ?

Private Function getMD5CheckSum(ByVal filePath As String) As String
        Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
        Dim f As FileStream = New FileStream(filePath.ToString, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
        f = New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
        md5.ComputeHash(f)
        Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
        Dim objFile = ObjFSO.GetFile(filePath.ToString)

        Dim hash As Byte() = md5.Hash
        Dim buff As StringBuilder = New StringBuilder
        Dim hashByte As Byte
        For Each hashByte In hash
            buff.Append(String.Format("{0:X1}", hashByte))
        Next
        objFile = Nothing
        f.Close()
        f = Nothing
        getMD5CheckSum = buff.ToString()
End Function

Share this post


Link to post
Share on other sites
Gurzi

Fixed.

Podem fechar :)

Solução :

Private Function getMD5CheckSum(ByVal filePath As String) As String
        Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
        Dim f As FileStream 
        f = New FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
        md5.ComputeHash(f)

        Dim hash As Byte() = md5.Hash
        Dim buff As StringBuilder = New StringBuilder
        Dim hashByte As Byte
        For Each hashByte In hash
            buff.Append(String.Format("{0:X1}", hashByte))
        Next

        f.Close()
        f = Nothing
        getMD5CheckSum = buff.ToString()
End Function

Copy paste dá sempre mau resultado  :wallbash:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.