Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Getting problems with vb.net codings..help, Object reference not set to an instance

views
     
TSjai1210
post Jan 18 2006, 08:22 PM, updated 19y ago

Getting Started
**
Junior Member
63 posts

Joined: Mar 2005
From: ss2, petaling jaya


I am getting problems with having an unhandled exception occured when trying to execute my vb.net projects. Anyone know how to solve it??

The following is the exception Details:

System.NullReferenceException: Object reference not set to an instance of an object.
TSjai1210
post Jan 18 2006, 08:25 PM

Getting Started
**
Junior Member
63 posts

Joined: Mar 2005
From: ss2, petaling jaya


following is my codes ....




Public Sub InsertRecord()


Dim strFileName As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim strDirectoryName As String = C:\Inetpub\wwwroot\....\"

If (Not (File1.PostedFile Is Nothing)) AndAlso (File1.PostedFile.ContentLength > 0) Then
Try
File1.PostedFile.SaveAs(strDirectoryName + strFileName)

Catch ex As Exception
End Try

Else
LblPopUpMsg.Text = "please select a file to upload"
End If

TSjai1210
post Jan 18 2006, 08:28 PM

Getting Started
**
Junior Member
63 posts

Joined: Mar 2005
From: ss2, petaling jaya


Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:
Dim strFileName As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim strDirectoryName As String = "C:\Inetpub\...\"



Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
BadSystem.AddDocument.InsertRecord() in C:\Inetpub\wwwroot\BadSystem\AddDocument.aspx.vb:140
BadSystem.AddDocument.btnSave_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\BadSystem\AddDocument.aspx.vb:71
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()



sheeeng
post Jan 18 2006, 08:31 PM

ソフト エンジニア
****
Senior Member
688 posts

Joined: Feb 2005
From: クアラルンプール
QUOTE(jai1210 @ Jan 18 2006, 08:22 PM)
I am getting problems with having an unhandled exception occured when trying to execute my vb.net projects. Anyone know how to solve it??

The following is the exception Details:

System.NullReferenceException: Object reference not set to an instance of an object.
*
Usually this error pops up when u have not declare for new instance of object.

for example....

u must put....

Dim stu_name1 as new Student. (if this line lost then error)

B4 using it...

stu_name1.first_name = "Sam"

HTH


TSjai1210
post Jan 18 2006, 08:35 PM

Getting Started
**
Junior Member
63 posts

Joined: Mar 2005
From: ss2, petaling jaya


the error is point that the the HTML control input File is not declared as new class.

so how do it to declare new class for the HTML contriol? Following is the codes...can u help me declare new class for it...i really got stucks of this..

Dim strFileName As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
TSjai1210
post Jan 18 2006, 08:53 PM

Getting Started
**
Junior Member
63 posts

Joined: Mar 2005
From: ss2, petaling jaya


Anyone know how to declare new member for

Dim strFileName As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
PrinceHamsap
post Jan 18 2006, 11:02 PM

Legendary
******
Senior Member
1,637 posts

Joined: Jan 2003
From: Munich , Bangkok, Barcelona , KualaLumpur


wat version of ASP.NET u using?

if v1.0 must set enctype = something ... i forget alredi tongue.gif
TSjai1210
post Jan 18 2006, 11:47 PM

Getting Started
**
Junior Member
63 posts

Joined: Mar 2005
From: ss2, petaling jaya


I use vb.net for writing my coding...so?
yingchai
post Jan 19 2006, 01:50 AM

Regular
******
Senior Member
1,281 posts

Joined: Jul 2005

QUOTE(PrinceHamsap @ Jan 18 2006, 11:02 PM)
wat version of ASP.NET u using?

if v1.0 must set enctype = something ... i forget alredi tongue.gif
*
i tot only hav v1.1 or 2.0...correct me if i m wrong

QUOTE(jai1210 @ Jan 18 2006, 11:47 PM)
I use vb.net for writing my coding...so?
*
i suspect u declare ur class together wif ur HTML control codings
try doing it seperately, ur server-side coding in 1 file n ur class declaration in another file

hope it helps...

alvinz_c
post Jan 24 2006, 08:36 AM

Casual
***
Junior Member
407 posts

Joined: Oct 2004
Hi, Jai.. try go to the aspx HTML view, add runat="server" attribute in your <input type="file"> to be HTML server control. You need to create a HtmlInputFile class in your code behind in order to use the File1.PostedFile.FileName.

1. Add runat="server" in the <input type="file"> in HTML view
2. Swtich to Design View
3. Go to code-behind, you will see an HtmlInputFile class will be automatically imported.


Good luck !

 

Change to:
| Lo-Fi Version
0.0181sec    0.41    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 05:57 PM