Sending a byte[] as response in webapp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Clauss

    #1

    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.Redir ect()) 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
    cabadam@tamu.ed u



  • helmut fish

    #2
    Re: Sending a byte[] as response in webapp

    Try Response.Binary Write()

    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" <cabadam@nospam .tamu.edu> wrote in message
    news:%235BESIGR FHA.2384@tk2msf tngp13.phx.gbl. ..[color=blue]
    > 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.Redir ect()) 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
    > cabadam@tamu.ed u
    >
    >
    >[/color]


    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: Sending a byte[] as response in webapp

      hi,

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

      Response.Clear( );
      Response.Conten tType = "applicatio n/vnd.ms-excel";
      string file = Session["ReportFile "].ToString();
      Response.Append Header( "content-disposition", "inline;filenam e=" +
      file.Substring( file.LastIndexO f( @"\")+1) );
      FileStream fileStream = new FileStream( file , FileMode.Open);
      byte[] buffer = new Byte[4096];
      while( fileStream.Read (buffer, 0, 4096)>0 )
      Response.Binary Write( buffer);
      fileStream.Clos e();
      Response.End();


      Cheers,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation


      "helmut fish" <fish@xtra.co.n z> wrote in message
      news:u7grAYGRFH A.1528@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Try Response.Binary Write()
      >
      > 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" <cabadam@nospam .tamu.edu> wrote in message
      > news:%235BESIGR FHA.2384@tk2msf tngp13.phx.gbl. ..[color=green]
      >> 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.Redir ect()) 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
      >> cabadam@tamu.ed u
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      Working...