Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Passing a binary file(stream) to the presentation layer

Passing a binary file(stream) to the presentation layer

Scheduled Pinned Locked Moved C#
databasesysadminhelptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    roy_huntley
    wrote on last edited by
    #1

    Hi. I have a requirement to store files (they happen to be .pdf files but could be word/excel etc) on an application server. These files are to be requested from the presentation layer. When the user clicks a report, a reportid is passed to the middle tier, whereby it retrieves the associated filepath from the DB and then goes and loads the file. My problem is that I am not sure how to pass this file back to the presentation layer. What I would like to do, is spit out a stream to the response object so the file just opens in the users browser (rather than saving a copy on the web server and then allowing the user to either Open/Save). I thought a filestream or binaryreader object would do the trick, but if i pass this to the presentation layer, the second i call the .Read methods, ill get an exception as the file doesnt exist on the web server ! Can anybody suggest the best way(s) of achieving my goals ? Thanks.

    N 1 Reply Last reply
    0
    • R roy_huntley

      Hi. I have a requirement to store files (they happen to be .pdf files but could be word/excel etc) on an application server. These files are to be requested from the presentation layer. When the user clicks a report, a reportid is passed to the middle tier, whereby it retrieves the associated filepath from the DB and then goes and loads the file. My problem is that I am not sure how to pass this file back to the presentation layer. What I would like to do, is spit out a stream to the response object so the file just opens in the users browser (rather than saving a copy on the web server and then allowing the user to either Open/Save). I thought a filestream or binaryreader object would do the trick, but if i pass this to the presentation layer, the second i call the .Read methods, ill get an exception as the file doesnt exist on the web server ! Can anybody suggest the best way(s) of achieving my goals ? Thanks.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You make no mention what your presentation layer is, however from the context I assume you mean a web page. If you set the Response.ContentType to the proper file type and use Response.OutputStream it should work.

      R 1 Reply Last reply
      0
      • N Not Active

        You make no mention what your presentation layer is, however from the context I assume you mean a web page. If you set the Response.ContentType to the proper file type and use Response.OutputStream it should work.

        R Offline
        R Offline
        roy_huntley
        wrote on last edited by
        #3

        Sorry, yes, an ASP.Net web page. Im am OK with sending the stream to the response object once ive got it...my problem is actually getting the stream object from the middletier in the first place. PresLayer - Requests doc id 1 AppLayer - Receives Request - Obtains the path of the file from the db - can open the file (filestream?) - RETURNS THE FILE/STREAM PresLayer - Spits stream out to response object. My question is how i can pass the binary data back from the applayer to the preslayer. Eg, surely if i pass the filestream back (as an out parameter for example), the minute i call .Read on the front end, ill get an exception because the file actually exists on another machine ?!

        N 1 Reply Last reply
        0
        • R roy_huntley

          Sorry, yes, an ASP.Net web page. Im am OK with sending the stream to the response object once ive got it...my problem is actually getting the stream object from the middletier in the first place. PresLayer - Requests doc id 1 AppLayer - Receives Request - Obtains the path of the file from the db - can open the file (filestream?) - RETURNS THE FILE/STREAM PresLayer - Spits stream out to response object. My question is how i can pass the binary data back from the applayer to the preslayer. Eg, surely if i pass the filestream back (as an out parameter for example), the minute i call .Read on the front end, ill get an exception because the file actually exists on another machine ?!

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Provided that permissions are set correctly you should be able to read the file into a stream and pass it to your presentation layer for display via Response.OutputStream

          U 1 Reply Last reply
          0
          • N Not Active

            Provided that permissions are set correctly you should be able to read the file into a stream and pass it to your presentation layer for display via Response.OutputStream

            U Offline
            U Offline
            User 461006
            wrote on last edited by
            #5

            y dunn u pass a byte array frm the Business Layer to the presentation layer? Read the contents in the business layer into a byte array and pass that array to the presentation layer and use ur logic to display the content.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups