Link to home
Start Free TrialLog in
Avatar of Ruffone
Ruffone

asked on

Keep file data consistent

I am adding image file data to database. On another pass I am checking the file name and file length of the file on disk against the equivalent data that I have stored in the database. The file name match up but the length does not. There is consistently a one byte difference between the number stored in the database and the length returned from the file on disk. Could anyone advise me as to where this extra byte comes from and how I might keep them consistent.
Avatar of Death_Rat
Death_Rat
Flag of United States of America image

I am throwing this out there for those who want to argue about it. Even though is the same file, it is located in a different place, even if it is on the same drive. This new location would make a change in the file structure, thus increasing or decreasing the file size. If the issue is with less than 10 bytes, I wouldn't sweat it unless you have written code that would require it to be exact.
Avatar of Ruffone
Ruffone

ASKER

That is my issue. I am checking the folder for files that are not yet in the database. The file names are unique but I wanted to go that extra step and compare there lengths. Any work around to suggest
How are you copying the bytes from the file on disk into the databse?
Avatar of Ruffone

ASKER

This is the function I am using to recover the data from the file
    Public Shared Function ReadFile(ByVal filename As String) As Byte()
        Using fs As New FileStream(filename, FileMode.Open, FileAccess.Read)
            Dim fileContents As Byte() = New Byte(fs.Length) {}
            fs.Read(fileContents, 0, Convert.ToInt32(fs.Length))
            fs.Close()
            Return fileContents
        End Using
    End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ruffone
Ruffone

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