私は本当にこれに苦労しており、どんな助けでも大歓迎です。フォルダからSQLデータベースにファイルを保存するWindowsフォームVB EF
フォルダ内の各ファイルを通過してデータベースに保存するコードが必要です。コードを後で引き出して表示することができます。私はまだデータベースにファイルを取得しようとする笑、表示部分に持っていない。
私がこれまで
Value of type '1-dimensional array of Byte' cannot be converted to 'String'.
私にエラーを与えているしているどのようなデータベース内のすべてのフィールドは、おそらく、私はすべて間違ってこれをやっているnvarchar(MAX)
Dim dir As New System.IO.DirectoryInfo("C:\Users\Will\Desktop\SUBARU")
For Each f As System.IO.FileInfo In dir.GetFiles("*.*")
Using db As New FileStoreAppDBEntities
Dim NewFile As New StoredFile
NewFile.FileName = f.Name
NewFile.FileSize = f.Length
'got trouble here
Dim ImageData As Byte() = System.IO.File.ReadAllBytes(f.FullName)
NewFile.FileContent = ImageData
'
NewFile.FileType = f.Extension
db.StoredFiles.AddObject(NewFile)
db.SaveChanges()
End Using
Next
ていますか?
ご協力いただきありがとうございます。
--edit
これはそれを行うようです!
For Each f As System.IO.FileInfo In dir.GetFiles("*.*")
Using db As New FileStoreAppDBEntities
Dim NewFile As New StoredFile
NewFile.FileName = f.Name
NewFile.FileSize = f.Length
Dim filename As String = f.FullName
NewFile.FileContent = System.IO.File.ReadAllBytes(filename)
NewFile.FileType = f.Extension.ToLower
db.StoredFiles.AddObject(NewFile)
db.SaveChanges()
End Using
Next
ないパフォーマンスに確認してくださいしかし、私は、これは、代わりにストリーミングのそれを送るメモリ内のファイルを置くかもしれないと思いますか?
し、ファイル取得するには:
Using db As New FileStoreAppDBEntities
Dim IDofFile As Integer = 31
Dim getFile = (From files In db.StoredFiles Where files.FileID = IDofFile Select files).SingleOrDefault
'getFile.FileName eg. mydocument.txt
System.IO.File.WriteAllBytes("C:\LocationToSaveTo\" & getFile.FileName, getFile.FileContent)
End Using
は小さなファイルのために完璧に作業する非常に大きなファイルSystem.OutOfMemoryException
のエラーを取得するかの...おそらくファイルのアップをチャンク
は可能でしょうか?
...しかし、小さなファイルのために完璧に作業するSystem.OutOfMemoryExceptionに非常に大きなファイルのエラーを取得しますこれはSQLサーバーです)。 EFはこれを行うツールではありません:http://stackoverflow.com/questions/10055280/sql-filestream-entity-framework-store-large-files –