473,396 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how adoStream writes from asp to asp.net?

Ben
Hello,

I have an asp routine to display an Excel worksheet on an
a web (asp) page. I have created aspx pages but only in
the classroom. Point - I have the basics for aspx. Could
someone show me how I would perform the routine below (asp
routine) in aspx? I have VS 2003. Is there a control I
would use instead of the adoStream, or stick with
adoStream?

<%
If Session("LoggedIn") = True Then
Session("LoggedIn") = False
Response.ContentType ="application/vnd.ms-excel"
Path = "C:\MyFiles\MyExcel.xls"
Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(Path)
Response.BinaryWrite adoStream.Read()
adoStream.Close: Set adoStream = Nothing
Response.End
Else
response.redirect("FirstPage.asp")
End If
%>

Thanks,
Ben
Nov 18 '05 #1
8 1544
"Ben" <an*******@discussions.microsoft.com> wrote in news:810a01c484a1
$a****************@phx.gbl:
Is there a control I
would use instead of the adoStream, or stick with
adoStream?


You would use a System.IO stream such as memoryStream to read a file off
the disk and send it through the http response object.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #2
Ben
May I ask for a hint what that would look like in
comparison to the asp code example using the adodb.stream
object?

Thanks,
B

-----Original Message-----
"Ben" <an*******@discussions.microsoft.com> wrote in news:810a01c484a1$a****************@phx.gbl:
Is there a control I
would use instead of the adoStream, or stick with
adoStream?

You would use a System.IO stream such as memoryStream to

read a file offthe disk and send it through the http response object.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.http://members.ebay.com/aboutme/coolspot18/
.

Nov 18 '05 #3
Ben
Well, I got this far. Found an example on the net, but I
don't know how to invoke the memorystream - the syntax. I
know how to declare the namespace for System.IO. That
would use the Imports key word. May I request the syntax
for using memorystream to open an Excel file?

Aspx example:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
End Sub
</script>
<html>
<head>
<title>ASP.NET Excel Sample</title>
</head>
<body>

<table>
<thead>
<tr>
<th bgcolor="blue"><font color="white">Name</font></th>
<th bgcolor="blue"><font color="white">Sales</font></th>
<th bgcolor="blue"><font
color="white">Commission</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe Shmo</td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Jane Shmo</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
</tbody>
</table>

</body>
</html>

Thanks,
B
-----Original Message-----
"Ben" <an*******@discussions.microsoft.com> wrote in news:810a01c484a1$a****************@phx.gbl:
Is there a control I
would use instead of the adoStream, or stick with
adoStream?

You would use a System.IO stream such as memoryStream to

read a file offthe disk and send it through the http response object.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.http://members.ebay.com/aboutme/coolspot18/
.

Nov 18 '05 #4
ASP.NET provides a method to do so. You could just use :

Response.ContentType="application/vnd.ms-excel"
Response.WriteFile "c:\MyPath\MyFile.xls"

instead of handling explictely file i/o operations...
Patrice

--

"Ben" <an*******@discussions.microsoft.com> a écrit dans le message de
news:7f****************************@phx.gbl...
Well, I got this far. Found an example on the net, but I
don't know how to invoke the memorystream - the syntax. I
know how to declare the namespace for System.IO. That
would use the Imports key word. May I request the syntax
for using memorystream to open an Excel file?

Aspx example:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
End Sub
</script>
<html>
<head>
<title>ASP.NET Excel Sample</title>
</head>
<body>

<table>
<thead>
<tr>
<th bgcolor="blue"><font color="white">Name</font></th>
<th bgcolor="blue"><font color="white">Sales</font></th>
<th bgcolor="blue"><font
color="white">Commission</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe Shmo</td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Jane Shmo</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
</tbody>
</table>

</body>
</html>

Thanks,
B
-----Original Message-----
"Ben" <an*******@discussions.microsoft.com> wrote in

news:810a01c484a1
$a****************@phx.gbl:
Is there a control I
would use instead of the adoStream, or stick with
adoStream?


You would use a System.IO stream such as memoryStream to

read a file off
the disk and send it through the http response object.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when

replying.
http://members.ebay.com/aboutme/coolspot18/
.

Nov 18 '05 #5
Ben
Thanks. I will try that. But what is vnd in

"application/vnd.ms-excel"


-----Original Message-----
ASP.NET provides a method to do so. You could just use :

Response.ContentType="application/vnd.ms-excel"
Response.WriteFile "c:\MyPath\MyFile.xls"

instead of handling explictely file i/o operations...
Patrice

--

"Ben" <an*******@discussions.microsoft.com> a écrit dans le message denews:7f****************************@phx.gbl...
Well, I got this far. Found an example on the net, but I don't know how to invoke the memorystream - the syntax. I know how to declare the namespace for System.IO. That
would use the Imports key word. May I request the syntax for using memorystream to open an Excel file?

Aspx example:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
End Sub
</script>
<html>
<head>
<title>ASP.NET Excel Sample</title>
</head>
<body>

<table>
<thead>
<tr>
<th bgcolor="blue"><font color="white">Name</font></th> <th bgcolor="blue"><font color="white">Sales</font></th> <th bgcolor="blue"><font
color="white">Commission</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe Shmo</td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Jane Shmo</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
</tbody>
</table>

</body>
</html>

Thanks,
B
>-----Original Message-----
>"Ben" <an*******@discussions.microsoft.com> wrote in

news:810a01c484a1
>$a****************@phx.gbl:
>
>> Is there a control I
>> would use instead of the adoStream, or stick with
>> adoStream?
>>
>
>You would use a System.IO stream such as memoryStream
to read a file off
>the disk and send it through the http response object.
>
>--
>Lucas Tam (RE********@rogers.com)
>Please delete "REMOVE" from the e-mail address when

replying.
>http://members.ebay.com/aboutme/coolspot18/
>.
>

.

Nov 18 '05 #6
Ben
I tried this method but the page was unreadable. Here is
what I tried:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
Response.WriteFile ("C:\Test\ExcelTest.xls")
End Sub
</script>
<html>
<head>
<title>Excel Test</title>
</head>
<body>

</body>
</html>

-------------------------------------------------------

here is something else I am going to try -- using a byte
array. Any comments/suggestions appreciated.
....
Dim fs As New FileStream(FilePath, FileMode.Open,
FileAccess.Read)
Dim bw As New System.IO.BinaryReader(fs)
Dim byt() As Byte
byt = bw.ReadBytes(cint(fs.Length))
Response.ContentType = "application/vnd.ms-excel"
Response.OutputStream.Write(byt, 0, length)
....

Ben
-----Original Message-----
ASP.NET provides a method to do so. You could just use :

Response.ContentType="application/vnd.ms-excel"
Response.WriteFile "c:\MyPath\MyFile.xls"

instead of handling explictely file i/o operations...
Patrice

--

"Ben" <an*******@discussions.microsoft.com> a écrit dans le message denews:7f****************************@phx.gbl...
Well, I got this far. Found an example on the net, but I don't know how to invoke the memorystream - the syntax. I know how to declare the namespace for System.IO. That
would use the Imports key word. May I request the syntax for using memorystream to open an Excel file?

Aspx example:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
End Sub
</script>
<html>
<head>
<title>ASP.NET Excel Sample</title>
</head>
<body>

<table>
<thead>
<tr>
<th bgcolor="blue"><font color="white">Name</font></th> <th bgcolor="blue"><font color="white">Sales</font></th> <th bgcolor="blue"><font
color="white">Commission</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe Shmo</td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Jane Shmo</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
</tbody>
</table>

</body>
</html>

Thanks,
B
>-----Original Message-----
>"Ben" <an*******@discussions.microsoft.com> wrote in

news:810a01c484a1
>$a****************@phx.gbl:
>
>> Is there a control I
>> would use instead of the adoStream, or stick with
>> adoStream?
>>
>
>You would use a System.IO stream such as memoryStream
to read a file off
>the disk and send it through the http response object.
>
>--
>Lucas Tam (RE********@rogers.com)
>Please delete "REMOVE" from the e-mail address when

replying.
>http://members.ebay.com/aboutme/coolspot18/
>.
>

.

Nov 18 '05 #7
Ben
Here is something that worked. Any advice appreciated on
hidden gotcha's to look for with this routine:

Imports System.IO

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
GetFile()
End Sub

Private Sub GetFile()
Dim FilePath As String = "C:\test\ExcelTest.xls"
Dim fs As New FileStream(FilePath, FileMode.Open,
FileAccess.Read)
Dim bw As New System.IO.BinaryReader(fs)
Dim byt() As Byte, i As Integer
byt = bw.ReadBytes(CInt(fs.Length))
i = byt.Length()
Response.ContentType = "application/vnd.ms-excel"
Response.OutputStream.Write(byt, 0, i)
Response.OutputStream.Close()
End Sub

End Class

The way this will work is that from another page I will
have multiple listboxes (I have several excel files
categorized in various directories). From listbox1 you
pick a category, listbox2 populates based on that
category, then you select a file, pass that file to the
next page which contains the routine above and display the
contents of the file.
-----Original Message-----
I tried this method but the page was unreadable. Here is
what I tried:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
Response.WriteFile ("C:\Test\ExcelTest.xls")
End Sub
</script>
<html>
<head>
<title>Excel Test</title>
</head>
<body>

</body>
</html>

-------------------------------------------------------

here is something else I am going to try -- using a byte
array. Any comments/suggestions appreciated.
....
Dim fs As New FileStream(FilePath, FileMode.Open,
FileAccess.Read)
Dim bw As New System.IO.BinaryReader(fs)
Dim byt() As Byte
byt = bw.ReadBytes(cint(fs.Length))
Response.ContentType = "application/vnd.ms-excel"
Response.OutputStream.Write(byt, 0, length)
....

Ben
-----Original Message-----
ASP.NET provides a method to do so. You could just use :

Response.ContentType="application/vnd.ms-excel"
Response.WriteFile "c:\MyPath\MyFile.xls"

instead of handling explictely file i/o operations...
Patrice

--

"Ben" <an*******@discussions.microsoft.com> a écrit dans le message de
news:7f****************************@phx.gbl...
Well, I got this far. Found an example on the net,
but I don't know how to invoke the memorystream - the syntax. I know how to declare the namespace for System.IO. That
would use the Imports key word. May I request the syntax for using memorystream to open an Excel file?

Aspx example:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
End Sub
</script>
<html>
<head>
<title>ASP.NET Excel Sample</title>
</head>
<body>

<table>
<thead>
<tr>
<th bgcolor="blue"><font color="white">Name</font></th> <th bgcolor="blue"><font color="white">Sales</font></th> <th bgcolor="blue"><font
color="white">Commission</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe Shmo</td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Jane Shmo</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
</tbody>
</table>

</body>
</html>

Thanks,
B

>-----Original Message-----
>"Ben" <an*******@discussions.microsoft.com> wrote in
news:810a01c484a1
>$a****************@phx.gbl:
>
>> Is there a control I
>> would use instead of the adoStream, or stick with
>> adoStream?
>>
>
>You would use a System.IO stream such as memoryStream to read a file off
>the disk and send it through the http response object.
>
>--
>Lucas Tam (RE********@rogers.com)
>Please delete "REMOVE" from the e-mail address when
replying.
>http://members.ebay.com/aboutme/coolspot18/
>.
>

.

.

Nov 18 '05 #8
As you want to stream an Excel file, you'll have to remove the HTML code.
Only the file must be sent...

Patrice

--

"Ben" <an*******@discussions.microsoft.com> a écrit dans le message de
news:86****************************@phx.gbl...
I tried this method but the page was unreadable. Here is
what I tried:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
Response.WriteFile ("C:\Test\ExcelTest.xls")
End Sub
</script>
<html>
<head>
<title>Excel Test</title>
</head>
<body>

</body>
</html>

-------------------------------------------------------

here is something else I am going to try -- using a byte
array. Any comments/suggestions appreciated.
....
Dim fs As New FileStream(FilePath, FileMode.Open,
FileAccess.Read)
Dim bw As New System.IO.BinaryReader(fs)
Dim byt() As Byte
byt = bw.ReadBytes(cint(fs.Length))
Response.ContentType = "application/vnd.ms-excel"
Response.OutputStream.Write(byt, 0, length)
....

Ben
-----Original Message-----
ASP.NET provides a method to do so. You could just use :

Response.ContentType="application/vnd.ms-excel"
Response.WriteFile "c:\MyPath\MyFile.xls"

instead of handling explictely file i/o operations...
Patrice

--

"Ben" <an*******@discussions.microsoft.com> a écrit dans le message denews:7f****************************@phx.gbl...
Well, I got this far. Found an example on the net, but I don't know how to invoke the memorystream - the syntax. I know how to declare the namespace for System.IO. That
would use the Imports key word. May I request the syntax for using memorystream to open an Excel file?

Aspx example:

<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Src as Object, E as EventArgs)
Response.ContentType = "application/vnd.ms-excel"
End Sub
</script>
<html>
<head>
<title>ASP.NET Excel Sample</title>
</head>
<body>

<table>
<thead>
<tr>
<th bgcolor="blue"><font color="white">Name</font></th> <th bgcolor="blue"><font color="white">Sales</font></th> <th bgcolor="blue"><font
color="white">Commission</font></th>
</tr>
</thead>
<tbody>
<tr>
<td>Joe Shmo</td>
<td>6420</td>
<td>=(B2 * 0.05)</td>
</tr>
<tr>
<td>Jane Shmo</td>
<td>3675</td>
<td>=(B3 * 0.05)</td>
</tr>
</tbody>
</table>

</body>
</html>

Thanks,
B
>-----Original Message-----
>"Ben" <an*******@discussions.microsoft.com> wrote in

news:810a01c484a1
>$a****************@phx.gbl:
>
>> Is there a control I
>> would use instead of the adoStream, or stick with
>> adoStream?
>>
>
>You would use a System.IO stream such as memoryStream
to read a file off
>the disk and send it through the http response object.
>
>--
>Lucas Tam (RE********@rogers.com)
>Please delete "REMOVE" from the e-mail address when

replying.
>http://members.ebay.com/aboutme/coolspot18/
>.
>

.

Nov 18 '05 #9

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

Similar topics

1
by: Vince C. | last post by:
Hi. I'm trying to put upload results from an HTML form into an ADO stream. I thought I could code the following (JavaScript): var s = Server.CreateObject("ADODB.Stream"); s.Type =...
13
by: TinyTim | last post by:
I'm a newbie at ASP & HTML. It seems that when you use server side code and you're going to return a customized HTML form with several fields and labels, you have to do an extensive amount of...
0
by: m vaughn | last post by:
I wanted to hold information about open files in a struct and be able pass it around, but the behavior is not what I would expect. Can someone tell me why this doesn't work? (Even better, what is...
5
by: Bruce Pullen | last post by:
DB2 7.2 (ESE) on AIX 5.2. In 3 weeks, we've seen the following : Tablespace name = SYSCATSPACE Direct writes = 150306 Direct write elapsed...
2
by: Michael D. Ober | last post by:
In a VB 2005 Console Application, can multiple threads write to the console without causing problems? I know this is a quick way to destabilize a Windows Forms application. Mike Ober.
3
by: john.enevoldson | last post by:
Hi, When running a job that inserts data into a particular table we are seeing a significant number of direct writes against the tablespace containing the table. This is the only table in the...
6
by: mcse jung | last post by:
Here is asample program that writes a program and then executes it. Do you knowof a much simpler way of writing a program that writes a program? """...
1
by: ssndk123 | last post by:
Hi, Using the UserPort program that changes permissions in XP so that I am able to write directly to the parallel port using assembler.. I'm trying to send out square wave pulses for x number...
1
by: jennisy | last post by:
Hi, all, There is a problem that during download file, if the file size is greater than 800kb, 500 error popup. But it is OK, if the file is less than 800kb. Can anyone give me a advice? Thanks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...

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.