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 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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....
|
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...
|
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...
|
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(.....);
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |