473,503 Members | 2,435 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use filestream?

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

Nov 19 '05 #1
2 8232
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...

"Daniel" <Da****@discussions.microsoft.com> ¼¶¼g©ó¶l¥ó·s»D:E0********************************* *@microsoft.com...
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

Nov 19 '05 #2
i have solve it, the solution is i forget to read by using stream.
thanks for ur respond.

"Lau Lei Cheong" wrote:
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...

"Daniel" <Da****@discussions.microsoft.com> ¼¶¼g©ó¶l¥ó·s»D:E0*********************** ***********@microsoft.com...
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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6799
by: Shawn | last post by:
Hi. I'm using a FileStream (instead of just the path to the xml file) to load an XmlDocument. I'm doing this because I need to be able to prevent other processes to update the file I'm working on....
3
6292
by: Muki Rapp | last post by:
Hi! In the example below, once the media is full, the FileSteam.WriteByte throws an exception and the code is designed to handle it. However, when the GC is invoked, it calls the Finalize of...
9
5836
by: Tom | last post by:
I am working with the this object as oppose to the StreamReader object becuase I need to access a file (to find the contents) while an external application is updating the file. When I was...
5
12725
by: Chris Fink | last post by:
How do I load a string into a FileStream without going to disk? For example, string abc = "This is a string"; How do I load abc into a FileStream? FileStream input = new FileStream(.....);
0
1523
by: lh | last post by:
The following method only works when i give the ASP.net account full permissions on the directory. It doesn't work when i give the directory Modify, Read &Execute, List Folder Contents, Read, and...
9
2132
by: ljlevend | last post by:
I have two questions related to FileStreams. 1. Is there any way to determine whether a file has the permissions that are required by a FileStream constructor? For example, given the following...
7
2285
by: Nathan Sokalski | last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving,...
9
2657
by: Tim_Mac | last post by:
hi, i'm not sure if i have chosen the best approach, but it seemed quite good to me. i have a collection class, containing business objects. the collection class is static and remains in-memory...
6
3207
by: rn5a | last post by:
What's the difference between the 'Stream' object & the 'FileStream' object? A file can be opened using the following code snippets: -------------------- 'create a File object & StreamReader...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.