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.