how to use filestream?

G

Guest

Hi all,

I have problem in using the filestream .

below is my sample code:
Dim s2 As New FileStream("C:Save\Grab.xls", FileMode.Open,
FileAccess.Read, FileShare.Read)
s2.Lock(0, 0)

Dim sFileType As String
Dim sFileName As String, i As Integer
Dim bytContent As Byte()
ReDim bytContent(s2.Length)

Dim NewAttachment As New WebTest.InfoDataAccessObject
With NewAttachment
.lAttachment_ID = CLng("1")
.sFileName = "Grab.xls"
.iFileSize = s2.Length
.bFileContent = bytContent
.sFileType = "application/vnd.ms-excel"
.UpdateNonExpiredInfoWithUpload()
End With
s2.Unlock(0, 0)

I sucessfully update the data into sql database in binary format.
but when i open it by using response property, the file is no longer
recognized format by excel.

Here is the way to read:
Response.ContentType = dr("FILE_TYPE").ToString
Response.OutputStream.Write(CType(dr("FILE_DATA"), Byte()), 0,
CInt(dr"FILE_SIZE")))
Response.AddHeader("Content-Disposition", "attachment;filename=" +
dr("FILE_NAME").ToString())

The excel content turn to all html code in it. How to solve it? Any ideas?

thank you.

Best regards,
Ocurnos
 
L

Lau Lei Cheong

I think you have to override Page.Render method to suppress generation of
normal HTML or they'll get appended to the end of the file, and make Excel
think it is corrupted. (Try using Hex-Editors to open the "corrupted" file
and you'll see...)

If this is JPG or so, the appended part will be silently ignored, but Excel
have some important information placed at the end of file, if they're not
the place it would be, Excel can't find it and starts to complain there's
some problem at the file...
 
G

Guest

i have solve it, the solution is i forget to read by using stream.
thanks for ur respond.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top