By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,598 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

Sending a byte[] as response in webapp

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.