Can't Figure Out What is Wrong

W

Wayne Wengert

I am getting the following error whe I run this upload process. Code is
below - error points to the
lblInfo.Text = "Failed uploading file"

line? The upload runs fine and the file is properly uploaded to the
"scores" directory? What is it complaining about?


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

=================== code =======================
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpload.Click

If Not (uploadedfile.PostedFile Is Nothing) Then

Try

Dim postedFile = uploadedfile.PostedFile

filename = Path.GetFileName(postedFile.FileName)

Dim contentType As String = postedFile.ContentType

Dim contentLength As Integer = postedFile.ContentLength

uploadedfile.PostedFile.SaveAs(Server.MapPath("./scores/" & filename))

'postedFile.SaveAs("./scores/" & filename)

lblInfo.Text = "Upload Successful!"

lblInfo.Visible = True

btnSave.Visible = True

Catch ex As Exception

lblInfo.Text = "Failed uploading file"

lblInfo.Visible = True

End Try

End If


End Sub
 
M

Michael H

On Sun, 27 Feb 2005 10:59:12 -0700, "Wayne Wengert"

I know this may be a silly question, but you do have the

<ASP:Label id="lblInfo" ....../>

in your HTML code for the page ? I don't recall the exact error
that'd be reported if you didn't but trying to call the Text property
of the Label object before instantiating it would give this error.




Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio
 
P

Patrick Olurotimi Ige

Wayne.. i'd say since u are getting :-
the error:-
System.NullReferenceException: Object reference not set
to an instance of an object.

Its possible Michael is right that u are not using lblInfo or something
related
Hope it helps
Patrick
 
W

Wayne Wengert

Michael;

Yes, lblInfo is there and is used without problem in some other Subs

Wayne
 
M

Michael H

Michael;

Yes, lblInfo is there and is used without problem in some other Subs

Wayne

Wayne,

Ok, does the problem go away if you just omit the


lblInfo.Text = "Failed uploading file"
lblInfo.Visible = True


?

It appears that you're stating that the lblInfo object is not null
before the catch block but null within it; if I'm understand you
correctly.


Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio
 
W

Wayne Wengert

The suggestions you all were giving me pointed to a problem with that label
(even though VSNET IDE saw it as far as autocomplete tasks?). Anyway, I
deleted the html code defining that label, saved and closed the solution. I
then re-opened the solution, used the toolbox to add the label back with the
same name and now it appears to work?

I have no idea what was wrong!

Thanks for all the suggestions.

Wayne
 
M

Michael H

The suggestions you all were giving me pointed to a problem with that label
(even though VSNET IDE saw it as far as autocomplete tasks?). Anyway, I
deleted the html code defining that label, saved and closed the solution. I
then re-opened the solution, used the toolbox to add the label back with the
same name and now it appears to work?

I have no idea what was wrong!

Thanks for all the suggestions.

Wayne


One of my thoughts was that you may have had a type-oh somewhere
pertaining to the Label but it's impossible to tell from my chair w/o
having saw your entire code. The good thing is that you got it to
work, but it'd be very nice to know what was crashing your app. to
avoid future problems.

Ciao,


Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top