Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6552841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:30:34+00:00 2026-05-25T12:30:34+00:00

I am having an issue with my ASHX handler that is generating PDF. When

  • 0

I am having an issue with my ASHX handler that is generating PDF.

When the user hits a “View PDF” button, it will look in the database for the PDF file and display it, but if there isn’t a PDF file there it should display a blank page saying “no PDF available”, but instead I get a “null reference” error on this line of code:

ms.WriteTo(context.Response.OutputStream)

Below is the code for the handler:

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    'This class takes the uniqueidentifier of an image stored in the SQL DB and sends it to the output stream
    'This saves storing copies of image files on the web server as well as in the DB
    context.Response.Clear()
    If context.Request.QueryString("fileSurveyID") IsNot Nothing Then
        Dim filesID As String = context.Request.QueryString("fileSurveyID")
        Dim fileName = String.Empty
        Dim ms As MemoryStream = GetPDFFile(filesID)
        context.Response.ContentType = "application/pdf"
        context.Response.AddHeader("Content-Disposition", "attachment;filename=" & fileName)
        context.Response.Buffer = True
        ms.WriteTo(context.Response.OutputStream)
        context.Response.End()
    Else
        context.Response.Write("<p>No pdf file</p>")
    End If
End Sub

Can anyone tell me how to get rid of this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:30:35+00:00Added an answer on May 25, 2026 at 12:30 pm

    Simple If..Then should do the trick:

    Dim ms As MemoryStream = GetPDFFile(filesID)
    If ms IsNot Nothing Then
        context.Response.ContentType = "application/pdf"
        context.Response.AddHeader("Content-Disposition", "attachment;filename=" & fileName)
        context.Response.Buffer = True
        ms.WriteTo(context.Response.OutputStream)
        context.Response.End()
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with a standard ASP.NET page that has a TextBox and
I'm having issue with Action Listener of a JTable that being updated according the
Having some issue with Threadpooling here that I need some help with please. I
We have a device that support SAE J1939 interface and having issue with finding
Having an issue applying the rules that rounders the upper-left and upper-right corners in
Having issue with my navigation. How can I prevent it? My CSS file looks
Im having issue with mail sending In web.config file <mailSettings> <smtp from=xxxx@companyname.com> <network host=mail.authsmtp.com
I'm having issue assigning regex value to a string. Issue that I have is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.