how adoStream writes from asp to asp.net?

Discussion in 'ASP .Net' started by Ben, Aug 17, 2004.

  1. Ben

    Ben Guest

    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
     
    Ben, Aug 17, 2004
    #1
    1. Advertising

  2. Ben

    Lucas Tam Guest

    "Ben" <> wrote in news:810a01c484a1
    $a35b7ea0$:

    > 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 ()
    Please delete "REMOVE" from the e-mail address when replying.
    http://members.ebay.com/aboutme/coolspot18/
     
    Lucas Tam, Aug 17, 2004
    #2
    1. Advertising

  3. Ben

    Ben Guest

    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" <> wrote in

    news:810a01c484a1
    >$a35b7ea0$:
    >
    >> 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 ()
    >Please delete "REMOVE" from the e-mail address when

    replying.
    >http://members.ebay.com/aboutme/coolspot18/
    >.
    >
     
    Ben, Aug 17, 2004
    #3
  4. Ben

    Ben Guest

    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" <> wrote in

    news:810a01c484a1
    >$a35b7ea0$:
    >
    >> 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 ()
    >Please delete "REMOVE" from the e-mail address when

    replying.
    >http://members.ebay.com/aboutme/coolspot18/
    >.
    >
     
    Ben, Aug 17, 2004
    #4
  5. Ben

    Patrice Guest

    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" <> a écrit dans le message de
    news:7f8a01c484ab$d8d1d200$...
    > 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" <> wrote in

    > news:810a01c484a1
    > >$a35b7ea0$:
    > >
    > >> 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 ()
    > >Please delete "REMOVE" from the e-mail address when

    > replying.
    > >http://members.ebay.com/aboutme/coolspot18/
    > >.
    > >
     
    Patrice, Aug 18, 2004
    #5
  6. Ben

    Ben Guest

    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" <> a écrit dans

    le message de
    >news:7f8a01c484ab$d8d1d200$...
    >> 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" <> wrote in

    >> news:810a01c484a1
    >> >$a35b7ea0$:
    >> >
    >> >> 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 ()
    >> >Please delete "REMOVE" from the e-mail address when

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

    >
    >
    >.
    >
     
    Ben, Aug 18, 2004
    #6
  7. Ben

    Ben Guest

    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" <> a écrit dans

    le message de
    >news:7f8a01c484ab$d8d1d200$...
    >> 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" <> wrote in

    >> news:810a01c484a1
    >> >$a35b7ea0$:
    >> >
    >> >> 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 ()
    >> >Please delete "REMOVE" from the e-mail address when

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

    >
    >
    >.
    >
     
    Ben, Aug 18, 2004
    #7
  8. Ben

    Ben Guest

    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" <> a écrit dans

    >le message de
    >>news:7f8a01c484ab$d8d1d200$...
    >>> 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" <> wrote in
    >>> news:810a01c484a1
    >>> >$a35b7ea0$:
    >>> >
    >>> >> 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 ()
    >>> >Please delete "REMOVE" from the e-mail address when
    >>> replying.
    >>> >http://members.ebay.com/aboutme/coolspot18/
    >>> >.
    >>> >

    >>
    >>
    >>.
    >>

    >.
    >
     
    Ben, Aug 18, 2004
    #8
  9. Ben

    Patrice Guest

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

    Patrice

    --

    "Ben" <> a écrit dans le message de
    news:867501c48538$492e7260$...
    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" <> a écrit dans

    le message de
    >news:7f8a01c484ab$d8d1d200$...
    >> 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" <> wrote in

    >> news:810a01c484a1
    >> >$a35b7ea0$:
    >> >
    >> >> 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 ()
    >> >Please delete "REMOVE" from the e-mail address when

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

    >
    >
    >.
    >
     
    Patrice, Aug 19, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Gonsalves
    Replies:
    15
    Views:
    733
    Alexey Smirnov
    Apr 9, 2007
  2. Vince C.
    Replies:
    1
    Views:
    229
    Vince C.
    Apr 4, 2004
  3. Scott Gordo

    asp writes csv WITHOUT complete file path?

    Scott Gordo, Mar 14, 2006, in forum: ASP General
    Replies:
    5
    Views:
    148
    Scott Gordo
    Mar 15, 2006
  4. Replies:
    3
    Views:
    162
    J. Gleixner
    Oct 22, 2007
  5. blini
    Replies:
    1
    Views:
    321
    Martin Honnen
    Apr 1, 2006
Loading...

Share This Page