Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I am always getting this error when

Status
Not open for further replies.

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=&quot;vb&quot; AutoEventWireup=&quot;false&quot; Codebehind=&quot;UploadFile.aspx.vb&quot; Inherits=&quot;myDotNetApp.UploadFile&quot;%>
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<title>UploadFile</title>
<meta content=&quot;Microsoft Visual Studio.NET 7.0&quot; name=&quot;GENERATOR&quot;>
<meta content=&quot;Visual Basic 7.0&quot; name=&quot;CODE_LANGUAGE&quot;>
<meta content=&quot;JavaScript&quot; name=&quot;vs_defaultClientScript&quot;>
<meta content=&quot; name=&quot;vs_targetSchema&quot;>
</HEAD>
<body MS_POSITIONING=&quot;GridLayout&quot;>
<form id=&quot;Form1&quot; method=&quot;post&quot; encType=&quot;multipart\form-data&quot; runat=&quot;server&quot;>
<input id=&quot;InputFile&quot; type=&quot;file&quot; runat=&quot;server&quot; name=&quot;inputfilecontrol&quot;>
<INPUT id=&quot;btnUpload&quot; type=&quot;button&quot; value=&quot;Upload File&quot; runat=&quot;server&quot; onserverclick=&quot;UploadFile&quot;>
<asp:textbox id=&quot;txtResult&quot; runat=&quot;server&quot; Width=&quot;161px&quot; Height=&quot;28px&quot;></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 &quot; Web Form Designer Generated Code &quot;

'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(&quot;c:\uploadedfile.gif&quot;)
txtResult.Text = &quot;fewhfher&quot;
' outerror.Visible = True
' Catch objError As Exception
' outerror.InnerHtml = &quot;error saving the file&quot;
' outerror.Visible = True
' End Try
End If
txtResult.Text = filename
End Sub
End Class


Kindly help asap
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top