title: Using memorystream to make a pdf download using VB.NET and Webforms
body: <p>I have a method that I wrote that calls a ReportServer and returns a byte array of a pdf of the report. This works. I know because I've used the same method to write a pdf to a file and save it locally. Here I want to write the file to a memory stream and offer it as a download.</p>
  
  <pre><code>    Try
          Dim ms As MemoryStream = New MemoryStream(report, 0, report.Length)
          ms.Position = 0
  
          Response.Clear()
          Response.Expires = 0
          Response.Buffer = True
          Response.AddHeader("Content-disposition", "attachment;filename=UserReport.pdf")
          Response.ContentType = "application/pdf"
          'ms.WriteTo(Response.OutputStream)
          Response.BinaryWrite(ms.ToArray())
          Response.End()
          HttpContext.Current.ApplicationInstance.CompleteRequest()
          'Response.Flush()
  
      Catch ex As Exception
          lblERRORMSG.Visible = True
          lblERRORMSG.Text = "Darn!" &amp; ex.Message
          Return
      End Try
  End Sub`
  </code></pre>
  
  <p>This code compiles, runs, and I can even set breakpoints that get hit. But when the button is clicked nothing happens. </p>