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 3287068
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:27:06+00:00 2026-05-17T20:27:06+00:00

Suggestion in either in C# or VB.NET is acceptable. I have a class to

  • 0

Suggestion in either in C# or VB.NET is acceptable.

I have a class to handle file download link ASP.NET project like the following:

Public Class AIUFileHandler    
    Public Shared Sub DownloadFileHandler(ByVal fileName As String, ByVal filePath As String)    
        Dim r As HttpResponse    
        r.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
        r.AddHeader("content-disposition", String.Format("attachment;filename={0}", fileName))
        r.TransmitFile(filePath)    
        r.[End]()    
    End Sub    
End Class

Then, I call that function from a code behind of an ASP.NET page like this:

Protected Sub btnGetForm_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetForm.Click
    Dim fileName = "test.docx"
    Dim filePath = Server.MapPath("~/pub/test.docx")  
    AIUFileHandler.DownloadFileHandler(fileName, filePath)
End Sub

I got this error message like this:

Object reference not set to an instance of an object.

r.ContentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"

But if I use it like this without making another class, it works:

Protected Sub btnGetForm_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnGetForm.Click
    Dim fileName = "test.docx"
    Dim filePath = Server.MapPath("~/pub/test.docx")  
    Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
    Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", fileName))
    Response.TransmitFile(filePath)
    Response.[End]()  
End Sub

What’s the problem with my class?

Thank you.

  • 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-17T20:27:06+00:00Added an answer on May 17, 2026 at 8:27 pm

    Replace

    Dim r As HttpResponse
    

    with

    Dim r as HttpResponse  = HttpContext.Current.Response
    

    in AIUFileHandler class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have repository class in asp.net mvc which has this, public Material GetMaterial(int id)
I have created a new VS2008 ASP.Net Web service project, with the default name
I have followed the suggestion in this question... [ How to handle checkboxes in
I've built ASP.NET Web Services in the past that either were publicly consumed, or
I have an Asp.Net MVC Web Application that I am developing. I have TeamCity
I have a asp.net 2.0 web app which calls a long running stored proc
Does anyone have any examples of using Sqlite with ASP.NET membership? I am building
So I am working on a project that uses a ASP.NET server and we
I am binding a GridView using a DataSource in asp.net, and i would like
This is with ASP.NET Web Forms .NET 2.0 - I have a situation that

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.