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 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/
>.
>
.
.