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. Web Development
  3. ASP.NET
  4. Send file to Client

Send file to Client

Scheduled Pinned Locked Moved ASP.NET
questionperformance
2 Posts 1 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.
  • T Offline
    T Offline
    troels_sorensen
    wrote on last edited by
    #1

    Hi. I'm using a third party made module to generate pdf files. The user clicks a button, The code generates a pdf i memory and now a want to be able to send the pdf as a file to the client in a way where he gets the popup where he can choose to view or save the file. When the pdf file is ready (in memory) I can use 2 methods. one to write the file physically to disk (to a Path or to a filestream) or one to get the file as a byte[]. I want to send the file to the client _without_ first writing the file to disk. I've bee trying to do this with a filestream and Response.WriteFile. But this results in nothing happens. If I write the file to disk first and the reload it in Response.WriteFile, then it works. So the question is: How can I send a file that is not on disk (only i memory) to the client without writing the file to disk?

    T 1 Reply Last reply
    0
    • T troels_sorensen

      Hi. I'm using a third party made module to generate pdf files. The user clicks a button, The code generates a pdf i memory and now a want to be able to send the pdf as a file to the client in a way where he gets the popup where he can choose to view or save the file. When the pdf file is ready (in memory) I can use 2 methods. one to write the file physically to disk (to a Path or to a filestream) or one to get the file as a byte[]. I want to send the file to the client _without_ first writing the file to disk. I've bee trying to do this with a filestream and Response.WriteFile. But this results in nothing happens. If I write the file to disk first and the reload it in Response.WriteFile, then it works. So the question is: How can I send a file that is not on disk (only i memory) to the client without writing the file to disk?

      T Offline
      T Offline
      troels_sorensen
      wrote on last edited by
      #2

      I found I solution my self: byte[] theData = theDoc.GetData(); Page.Response.ContentType = "application/pdf"; Page.Response.AppendHeader("content-disposition", "attachment; filename=MyPDF.PDF"); Page.Response.AppendHeader("content-length", theData.Length.ToString()); Page.Response.BinaryWrite(theData);

      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