473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Server Error: Object reference not set

SAL
I am getting the following ERROR in my WebApp on line 30:

Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------

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:
Line 28: public void Upload_click(object sender, System.EventArgs e)
Line 29: {
Line 30: if (uploadFile.PostedFile != null)
Line 31: {
Line 32: string test = uploadFile.PostedFile.FileName;
Source File: c:\documents and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs Line: 30

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
TestWebApp.test.Upload_click(Object sender, EventArgs e) in c:\documents
and settings\my documents\myprojects\web\project\testwebapp\test.a spx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
I thought I was doing something wrong in my WebApp, so I created a brand new
solution to test with I get the same error. Below is all the code for my
test. Basically, all this webpage has is a HTML File Field Control, and a
Web Forms Button Control on it. After you click the File Field and select
your file, then you click the Button which calls Upload_click. When it reads
if (uploadFile.PostedFile != null) is when I get the error.

I'm new with ASP.net and this seems pretty straight-forward, but I can't
seem to see what I am doing wrong. Can someone tell me what I am doing wrong?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

public void Upload_click(object sender, System.EventArgs e)
{
if (uploadFile.PostedFile != null)
{
string test = uploadFile.PostedFile.FileName;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false"
Inherits="TestWebApp.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT id="uploadFile" type="file">
<asp:Button id="Upload" OnClick="Upload_click" runat="server"
Text="Upload"></asp:Button>
</form>
</body>
</HTML>

Thanks,

Oct 6 '06 #1
3 2552
You are using uploadFile control to access your uploaded file, you should
use Request.Files as shown below

HttpFileCollection HttpFiles = Request.Files;

for (int i = 0; i < HttpFiles.Count; i ++)

{

HttpPostedFile _HttpPosted = HttpFiles[i];
if ( _HttpPosted.ContentLength 0 )

{

string lineText = string.Empty;

using (StreamReader sr = new StreamReader(_HttpPosted.InputStream))

{

//here you can use the stream directly and process the file, without saving
it to the server //or save it if that's your rquirement.

while (sr.Peek() >= 0)

{

lineText = sr.ReadLine();

}

}

}

}

Thanks

baski

"SAL" <SA*@discussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
>I am getting the following ERROR in my WebApp on line 30:

Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------

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:
Line 28: public void Upload_click(object sender, System.EventArgs e)
Line 29: {
Line 30: if (uploadFile.PostedFile != null)
Line 31: {
Line 32: string test = uploadFile.PostedFile.FileName;
Source File: c:\documents and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs Line: 30

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
TestWebApp.test.Upload_click(Object sender, EventArgs e) in c:\documents
and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
I thought I was doing something wrong in my WebApp, so I created a brand
new
solution to test with I get the same error. Below is all the code for my
test. Basically, all this webpage has is a HTML File Field Control, and a
Web Forms Button Control on it. After you click the File Field and select
your file, then you click the Button which calls Upload_click. When it
reads
if (uploadFile.PostedFile != null) is when I get the error.

I'm new with ASP.net and this seems pretty straight-forward, but I can't
seem to see what I am doing wrong. Can someone tell me what I am doing
wrong?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

public void Upload_click(object sender, System.EventArgs e)
{
if (uploadFile.PostedFile != null)
{
string test = uploadFile.PostedFile.FileName;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false"
Inherits="TestWebApp.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT id="uploadFile" type="file">
<asp:Button id="Upload" OnClick="Upload_click" runat="server"
Text="Upload"></asp:Button>
</form>
</body>
</HTML>

Thanks,

Oct 6 '06 #2

"SAL" <SAL@discYou are using uploadFile control to access your uploaded
file, you should
use Request.Files as shown below

HttpFileCollection HttpFiles = Request.Files;

for (int i = 0; i < HttpFiles.Count; i ++)

{

HttpPostedFile _HttpPosted = HttpFiles[i];
if ( _HttpPosted.ContentLength 0 )

{

string lineText = string.Empty;

using (StreamReader sr = new StreamReader(_HttpPosted.InputStream))

{

//here you can use the stream directly and process the file, without saving
it to the server //or save it if that's your rquirement.

while (sr.Peek() >= 0)

{

lineText = sr.ReadLine();

}

}

}

}

Thanks

baski
ussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
>I am getting the following ERROR in my WebApp on line 30:

Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------

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:
Line 28: public void Upload_click(object sender, System.EventArgs e)
Line 29: {
Line 30: if (uploadFile.PostedFile != null)
Line 31: {
Line 32: string test = uploadFile.PostedFile.FileName;
Source File: c:\documents and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs Line: 30

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
TestWebApp.test.Upload_click(Object sender, EventArgs e) in c:\documents
and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
I thought I was doing something wrong in my WebApp, so I created a brand
new
solution to test with I get the same error. Below is all the code for my
test. Basically, all this webpage has is a HTML File Field Control, and a
Web Forms Button Control on it. After you click the File Field and select
your file, then you click the Button which calls Upload_click. When it
reads
if (uploadFile.PostedFile != null) is when I get the error.

I'm new with ASP.net and this seems pretty straight-forward, but I can't
seem to see what I am doing wrong. Can someone tell me what I am doing
wrong?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

public void Upload_click(object sender, System.EventArgs e)
{
if (uploadFile.PostedFile != null)
{
string test = uploadFile.PostedFile.FileName;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false"
Inherits="TestWebApp.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT id="uploadFile" type="file">
<asp:Button id="Upload" OnClick="Upload_click" runat="server"
Text="Upload"></asp:Button>
</form>
</body>
</HTML>

Thanks,

Oct 6 '06 #3
SAL
Thanks Baski. I will give it a try.

"Baski" wrote:
>
"SAL" <SAL@discYou are using uploadFile control to access your uploaded
file, you should
use Request.Files as shown below

HttpFileCollection HttpFiles = Request.Files;

for (int i = 0; i < HttpFiles.Count; i ++)

{

HttpPostedFile _HttpPosted = HttpFiles[i];
if ( _HttpPosted.ContentLength 0 )

{

string lineText = string.Empty;

using (StreamReader sr = new StreamReader(_HttpPosted.InputStream))

{

//here you can use the stream directly and process the file, without saving
it to the server //or save it if that's your rquirement.

while (sr.Peek() >= 0)

{

lineText = sr.ReadLine();

}

}

}

}

Thanks

baski
ussions.microsoft.comwrote in message
news:37**********************************@microsof t.com...
I am getting the following ERROR in my WebApp on line 30:

Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------

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:
Line 28: public void Upload_click(object sender, System.EventArgs e)
Line 29: {
Line 30: if (uploadFile.PostedFile != null)
Line 31: {
Line 32: string test = uploadFile.PostedFile.FileName;
Source File: c:\documents and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs Line: 30

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
TestWebApp.test.Upload_click(Object sender, EventArgs e) in c:\documents
and settings\my
documents\myprojects\web\project\testwebapp\test.a spx.cs:30
System.Web.UI.WebControls.Button.OnClick(EventArgs e)

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
System.Web.UI.Page.ProcessRequestMain()
I thought I was doing something wrong in my WebApp, so I created a brand
new
solution to test with I get the same error. Below is all the code for my
test. Basically, all this webpage has is a HTML File Field Control, and a
Web Forms Button Control on it. After you click the File Field and select
your file, then you click the Button which calls Upload_click. When it
reads
if (uploadFile.PostedFile != null) is when I get the error.

I'm new with ASP.net and this seems pretty straight-forward, but I can't
seem to see what I am doing wrong. Can someone tell me what I am doing
wrong?
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TestWebApp
{
/// <summary>
/// Summary description for test.
/// </summary>
public class test : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

public void Upload_click(object sender, System.EventArgs e)
{
if (uploadFile.PostedFile != null)
{
string test = uploadFile.PostedFile.FileName;
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false"
Inherits="TestWebApp.test" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>test</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<INPUT id="uploadFile" type="file">
<asp:Button id="Upload" OnClick="Upload_click" runat="server"
Text="Upload"></asp:Button>
</form>
</body>
</HTML>

Thanks,


Oct 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daniel Rimmelzwaan | last post by:
I got the following server error, does anybody have an idea of what it means? Server Error in '/CreateJobFromFile' Application. ...
1
by: vijay | last post by:
Hi I am working on a web application. I have huge form where in I have filled some part of the form and after two hours again I started filling the rest of the form but I got the following error ...
2
by: James Wallace | last post by:
I hope that someone can help me out there with this problem. I get an itermittant problem with our web page that occurs about once every 10 to 15 days where the only way to fix the problem is to...
3
by: Web Team | last post by:
Server Error in '/netapps' Application. -------------------------------------------------------------------------------- Object reference not set to an instance of an object. Description: An...
14
by: Marcus | last post by:
I have a function that simply returns TRUE if it can connect to a particular Sql Server 2005 express, or FALSE if it cannot. I am getting some strange error codes returned when the computer that...
4
by: David Lozzi | last post by:
Howdy, I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel and Geoffrey LeBlond. Anyway, they have some instructions on how to setup application level error handling. Most...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
2
by: Richard Coltrane | last post by:
Hi there, Ive just implemented some application level exception handling in ASP.Net 2.0. I deliberately set up a null reference error in my code to see how this would be handled. Sure enough...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.