更新时间:2023-02-23 21:31:41
To Stream:Dim fs 作为 IO.FileStream
fs = 新 FileStream( 文件路径,FileMode.Open)
To字节数组:
*使用FileSystemDim readBytes(LengthYouWantToRead - 1 )作为 字节
fs .Read(readBytes, 0 ,LengthYouWantToRead)
*使用IO。文件Dim readBytes() As 字节
readBytes = IO.File.ReadAllBytes( 文件路径)
(FileStream示例)
如果你想阅读来自文件的4096字节,
这样编写你的代码:Dim readBytes( 4096 - 1 )作为 字节
fs.Read(readBytes, 0 , 4096 )
检查这些:
1. saving-and-retrieving-file-使用-FILESTREAM-SQL- server-2008.aspx [ ^ ]
2. add-and-reading-files-from-sql-server-2008-filestream [ ^ ]
您可以直接使用ReadAllBytes()
文件Stream的System.IO.File
的共享功能。请参阅以下代码:Dim _mFileBytes As Byte ()= System.IO.File.ReadAllBytes( 您的文件路径)
之后您可以直接保存此字节
数组(在数据库中的上述示例 _mFileBytes 中,其列具有数据类型Varbinary()
。
欲了解更多详情:如何在SQL Server数据库表(VB.NET)中插入字节数组。 [ ^ ]
我希望这会对你有所帮助。 :)
i want to ask..
how do i get stream from file in vb.net?
i want to save that stream in database..and in my database, i set data type varbinary (max) to save stream
hope you can help me :)
thanks very much
To Stream:Dim fs As IO.FileStream fs = New FileStream("File Path", FileMode.Open)
To Byte Array:
* Using FileSystemDim readBytes(LengthYouWantToRead - 1) As Byte fs.Read(readBytes, 0, LengthYouWantToRead)
* Using IO.FileDim readBytes() As Byte readBytes = IO.File.ReadAllBytes("File Path")
(FileStream Example)
If you want to read 4096 Bytes from file,
write your code like this:Dim readBytes(4096 - 1) As Byte fs.Read(readBytes, 0, 4096)
Check these out:
1. saving-and-retrieving-file-using-filestream-sql-server-2008.aspx[^]
2. adding-and-reading-files-from-sql-server-2008-filestream[^]
You can Directly useReadAllBytes()
Shared Function ofSystem.IO.File
insted of file Stream. See the below code :Dim _mFileBytes As Byte() = System.IO.File.ReadAllBytes("Your File Path")
After that you can directly save thisByte
Array (In above example _mFileBytes) in the Database with the column having Data TypeVarbinary()
.
For more Details : How to Insert Byte Array In SQL Server Database Table(VB.NET).[^]
I hope this will help you. :)