lpatnaik
Programmer
- Jul 11, 2002
- 53
I am always getting this error when i am uploading a file to my server:
System.NullReferenceException: Object reference not set to an instance of an object.
Code is UploadFile.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="UploadFile.aspx.vb" Inherits="myDotNetApp.UploadFile"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>UploadFile</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" encType="multipart\form-data" runat="server">
<input id="InputFile" type="file" runat="server" name="inputfilecontrol">
<INPUT id="btnUpload" type="button" value="Upload File" runat="server" onserverclick="UploadFile">
<asp:textbox id="txtResult" runat="server" Width="161px" Height="28px"></asp:textbox></form>
</body>
</HTML>
and code for UploadFile.aspx.vb(code behind file):
Public Class UploadFile
Inherits System.Web.UI.Page
Protected WithEvents InputFile As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents txtResult As System.Web.UI.WebControls.TextBox
Protected WithEvents btnUpload As System.Web.UI.HtmlControls.HtmlInputButton
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public Sub UploadFile(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim filename As String
If Not (InputFile.PostedFile Is Nothing) Then
' Try
'fileInput.PostedFile.SaveAs("c:\uploadedfile.gif"
txtResult.Text = "fewhfher"
' outerror.Visible = True
' Catch objError As Exception
' outerror.InnerHtml = "error saving the file"
' outerror.Visible = True
' End Try
End If
txtResult.Text = filename
End Sub
End Class
Kindly help asap
System.NullReferenceException: Object reference not set to an instance of an object.
Code is UploadFile.aspx:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="UploadFile.aspx.vb" Inherits="myDotNetApp.UploadFile"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>UploadFile</title>
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" encType="multipart\form-data" runat="server">
<input id="InputFile" type="file" runat="server" name="inputfilecontrol">
<INPUT id="btnUpload" type="button" value="Upload File" runat="server" onserverclick="UploadFile">
<asp:textbox id="txtResult" runat="server" Width="161px" Height="28px"></asp:textbox></form>
</body>
</HTML>
and code for UploadFile.aspx.vb(code behind file):
Public Class UploadFile
Inherits System.Web.UI.Page
Protected WithEvents InputFile As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents txtResult As System.Web.UI.WebControls.TextBox
Protected WithEvents btnUpload As System.Web.UI.HtmlControls.HtmlInputButton
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Public Sub UploadFile(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim filename As String
If Not (InputFile.PostedFile Is Nothing) Then
' Try
'fileInput.PostedFile.SaveAs("c:\uploadedfile.gif"
txtResult.Text = "fewhfher"
' outerror.Visible = True
' Catch objError As Exception
' outerror.InnerHtml = "error saving the file"
' outerror.Visible = True
' End Try
End If
txtResult.Text = filename
End Sub
End Class
Kindly help asap