Outline ·
[ Standard ] ·
Linear+
Getting problems with vb.net codings..help, Object reference not set to an instance
TSjai1210
|
Jan 18 2006, 08:25 PM
|
Getting Started
|
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
|
Jan 18 2006, 08:28 PM
|
Getting Started
|
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
|
Jan 18 2006, 08:31 PM
|
|
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
|
Jan 18 2006, 08:35 PM
|
Getting Started
|
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
|
Jan 18 2006, 08:53 PM
|
Getting Started
|
Anyone know how to declare new member for
Dim strFileName As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
|
|
|
|
PrinceHamsap
|
Jan 18 2006, 11:02 PM
|
|
wat version of ASP.NET u using? if v1.0 must set enctype = something ... i forget alredi
|
|
|
|
TSjai1210
|
Jan 18 2006, 11:47 PM
|
Getting Started
|
I use vb.net for writing my coding...so?
|
|
|
|
yingchai
|
Jan 19 2006, 01:50 AM
|
|
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 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
|
Jan 24 2006, 08:36 AM
|
|
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 !
|
|
|
|