473,382 Members | 1,078 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,382 software developers and data experts.

Sending a byte[] as response in webapp

Alright, I have a webapp in which I need to send a byte[] (which happens to
be the contents of an excel spreadsheet read in from the .xls file).

Now, I can't actually redirect the user (Response.Redirect()) to the file,
so I want to just send the byte[] itself.

My question is, Response.Write() only takes a char[], so how can I send this
byte[]? (And what other headers might I need to set since I'm doing this
sorta manually?)

Thanks!

--
Adam Clauss
ca*****@tamu.edu

Nov 17 '05 #1
2 1844
Try Response.BinaryWrite()

Visual Programming Ltd Ibex PDF Creator - High speed scalable XSL-FO mail PO
Box 22-222, Khandallah, Wellington, New Zealand site Level 2, 2 Ganges Road,
Khandallah, Wellington, New Zealand phone +64 4 479 1738 fax +64 4 479 1294
web http://www.xmlpdf.com
"Adam Clauss" <ca*****@nospam.tamu.edu> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Alright, I have a webapp in which I need to send a byte[] (which happens
to be the contents of an excel spreadsheet read in from the .xls file).

Now, I can't actually redirect the user (Response.Redirect()) to the file,
so I want to just send the byte[] itself.

My question is, Response.Write() only takes a char[], so how can I send
this byte[]? (And what other headers might I need to set since I'm doing
this sorta manually?)

Thanks!

--
Adam Clauss
ca*****@tamu.edu

Nov 17 '05 #2
hi,

also you need to set the correct content/type, here is an example:

Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
string file = Session["ReportFile"].ToString();
Response.AppendHeader( "content-disposition", "inline;filename=" +
file.Substring( file.LastIndexOf( @"\")+1) );
FileStream fileStream = new FileStream( file , FileMode.Open);
byte[] buffer = new Byte[4096];
while( fileStream.Read(buffer, 0, 4096)>0 )
Response.BinaryWrite( buffer);
fileStream.Close();
Response.End();
Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"helmut fish" <fi**@xtra.co.nz> wrote in message
news:u7**************@TK2MSFTNGP09.phx.gbl...
Try Response.BinaryWrite()

Visual Programming Ltd Ibex PDF Creator - High speed scalable XSL-FO mail
PO Box 22-222, Khandallah, Wellington, New Zealand site Level 2, 2 Ganges
Road, Khandallah, Wellington, New Zealand phone +64 4 479 1738 fax +64 4
479 1294 web http://www.xmlpdf.com
"Adam Clauss" <ca*****@nospam.tamu.edu> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Alright, I have a webapp in which I need to send a byte[] (which happens
to be the contents of an excel spreadsheet read in from the .xls file).

Now, I can't actually redirect the user (Response.Redirect()) to the
file, so I want to just send the byte[] itself.

My question is, Response.Write() only takes a char[], so how can I send
this byte[]? (And what other headers might I need to set since I'm doing
this sorta manually?)

Thanks!

--
Adam Clauss
ca*****@tamu.edu


Nov 17 '05 #3

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

Similar topics

2
by: Frostillicus | last post by:
I'm trying to get an ASP to return a zip file to the remote browser from an Image (BLOB) field in SQL Server 2000 but Internet Explorer keeps saying: Cannot open C:\Documents and...
3
by: Danny Tuppeny | last post by:
Hi all, I'm trying to send a null character as a string delimiter through a TcpClient (code below). It's to connect to this poker bot room: http://games.cs.ualberta.ca/webgames/poker/bots.html...
7
by: Jay Douglas | last post by:
Hello all, I have a asp.net page that creates a pdf on the fly and sends the pdf down to the browser. When calling the page up in IE the Page_Load event is fried twice. This doesn't happen with...
7
by: Bob Garbados | last post by:
I need to construct an xml document, send it to a service over tcp/ip to a specified port, receive the xml response, and process the xml response. I can create the xml document to send, but what's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.