473,396 Members | 2,036 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,396 software developers and data experts.

Problem checking the lenght of a string

My code in the convert.aspx.cs page:

private void Page_Load(object sender, System.EventArgs e)
{
string sFile = Request.QueryString["File"];

if (sFile.Length > 0) <--- Error here.
{
Response.Write(sFile);
}
else
{
Response.Write("No file");
}
}

Causes

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

If I take out the "if" statement and just put

Response.Write(sFile);

Then it works fine. What is causing this error?

Thanks!
Nov 18 '05 #1
3 1007
vbMark,

If the request contains nothing at all then the string sFile is Nothing.

Checking the length on a string object = Nothing causes this error. You
either need to check if the string is not nothing and then do your length
check, or just check that it isn't nothing and skip the length check all
together.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
My code in the convert.aspx.cs page:

private void Page_Load(object sender, System.EventArgs e)
{
string sFile = Request.QueryString["File"];

if (sFile.Length > 0) <--- Error here.
{
Response.Write(sFile);
}
else
{
Response.Write("No file");
}
}

Causes

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

If I take out the "if" statement and just put

Response.Write(sFile);

Then it works fine. What is causing this error?

Thanks!

Nov 18 '05 #2
I would guess that the value that you are searching for in the QueryString is null. Check your spelling/case.

"vbMark" wrote:
My code in the convert.aspx.cs page:

private void Page_Load(object sender, System.EventArgs e)
{
string sFile = Request.QueryString["File"];

if (sFile.Length > 0) <--- Error here.
{
Response.Write(sFile);
}
else
{
Response.Write("No file");
}
}

Causes

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

If I take out the "if" statement and just put

Response.Write(sFile);

Then it works fine. What is causing this error?

Thanks!

Nov 18 '05 #3
Yeah, it's null. Thanks.

"=?Utf-8?B?SmltIEhlYXZleQ==?=" <Ji*******@discussions.microsoft.com>
wrote in news:A0**********************************@microsof t.com:
I would guess that the value that you are searching for in the
QueryString is null. Check your spelling/case.

"vbMark" wrote:
My code in the convert.aspx.cs page:

private void Page_Load(object sender, System.EventArgs e)
{
string sFile = Request.QueryString["File"];

if (sFile.Length > 0) <--- Error here.
{
Response.Write(sFile);
}
else
{
Response.Write("No file");
}
}

Causes

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

If I take out the "if" statement and just put

Response.Write(sFile);

Then it works fine. What is causing this error?

Thanks!


--
http://www.vbmark.com/
A good place to start.
Nov 18 '05 #4

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

Similar topics

16
by: Ling Lee | last post by:
Hello. I'm trying to write a small program that lets you put in a number as an integer and then it tells you the textuel representation of the number. Like if your input is 42, it will say...
2
by: Kevin Auch | last post by:
Hi all, I have a problem (a simple but incredible problem !). On a form, I have a Select element which is mulitple. I tried to get the number of options of this Select but it always return...
12
by: Pudlik, Szymon | last post by:
Hi, I've written some code: function onSubmit(form){ for (var i = 0; i < form.elements.lenght; i++){ if (form.elements.disabled == 1) form.elements.disabled = 0; }
1
by: jorntk | last post by:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <string.h> /*limit the lenght of input to 256 character and number of argument to 10*/ #define MAX...
12
by: Vicky | last post by:
What is the better way of checking blank string is it strvar.lenght > 0 or strvar == "" or something else Thnaks
3
by: Baz | last post by:
Hi All, Below is some sample code from a .NET sub I created. It seems to work OK, but sometimes when I call the routine and pass it a string, the actual data written to the file is followed by a...
10
by: tvin | last post by:
Hi all I brought a string from a .txt file which was saved like utf-8. In the .txt file i have this string "frédéric".My problem is that when i read this file .txt,the bytes of é are like...
9
by: Andrey Koptyaev | last post by:
What does it mean "fieldRequired.lenght" in php 4.1 ? I know "fieldRequired->lenght" but don't know "fieldRequired.lenght" Please help to understand. Thank you!
4
by: javaalien | last post by:
Could someone please help me how to count lenght string in a file? I have input file like this: 1039387845 35368535615253 695 .... Kindly pls assist me how to count the lenght. Thank you in...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.