[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Keep file data consistent

Posted on 2009-05-01
5
Medium Priority
?
175 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:ruffone
  • 3
5 Comments
 
LVL 2

Expert Comment

by:Death_Rat
ID: 24282742
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.
0
 
LVL 4

Author Comment

by:ruffone
ID: 24282826
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
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 24283170
How are you copying the bytes from the file on disk into the databse?
0
 
LVL 4

Author Comment

by:ruffone
ID: 24283541
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

0
 
LVL 4

Accepted Solution

by:
ruffone earned 0 total points
ID: 24288490
This fixed the problem
Dim fileContents() As Byte = New Byte((fs.Length) - 1) {}
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month20 days, 5 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question