By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

system.drawing error. Need help debugging.

P: n/a
I'm modyfying an image upload and resizing script that we've had laying
around for a long while.

I'm getting a NullReferenceException error (see full error at bottom) from
this line:
Dim g As System.Drawing.Image =
System.Drawing.Image.FromFile(strTempFullFileName)

I'm not sure what I should be checking for based on that error. There is a
file located where 'strTempFullFileName' points to.

Any suggestions on what else to check for would be appreciated.

-Darrel

FULL ERROR:

[NullReferenceException: Object reference not set to an instance of an
object.]
imageUpload.ImageUpload.btnUpload_Click(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\CourtsCMS\imageUpload\ImageUplo ad.aspx.vb:552
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292
Feb 22 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Darrel,

Did you set a breakpoint at this line to make sure that strTempFullFileName
is not null?

Eliyahu

"darrel" <no*****@nowhere.com> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl...
I'm modyfying an image upload and resizing script that we've had laying
around for a long while.

I'm getting a NullReferenceException error (see full error at bottom) from
this line:
Dim g As System.Drawing.Image =
System.Drawing.Image.FromFile(strTempFullFileName)

I'm not sure what I should be checking for based on that error. There is a
file located where 'strTempFullFileName' points to.

Any suggestions on what else to check for would be appreciated.

-Darrel

FULL ERROR:

[NullReferenceException: Object reference not set to an instance of an
object.]
imageUpload.ImageUpload.btnUpload_Click(Object sender, EventArgs e) in
C:\Inetpub\wwwroot\CourtsCMS\imageUpload\ImageUplo ad.aspx.vb:552
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292

Feb 22 '06 #2

P: n/a
Without seeing your code, you will need to Upload the file, save it
someplace, then load from where you saved the image. Also try this:

Dim g as New System.Drawing.Image
g = System.Drawing.Image.FromFile(strTempFullFileName)

Could you post the code on where you are getting strTempFullFileName
from? Feel free to check out
http://www.easerve.com/developer/tut...mage-file.aspx.
That article has a decent tutorial of how to upload an image with
vb.net

HTH,
Darren Kopp
http://blog.secudocs.com/

Feb 22 '06 #3

P: n/a
Did you set a breakpoint at this line to make sure that
strTempFullFileName
is not null?


Yep. The error comes from this specific line, and strTempFullFileName does
resolve to a full file path that does point to the specific file.

-Darrel
Feb 22 '06 #4

P: n/a
> Without seeing your code, you will need to Upload the file, save it
someplace, then load from where you saved the image.
Right. That's what this line is doing, grabbing the file that I've already
uploaded. The STR does resolve to a full path that does point at the file:

D:\Web\Applications\assets\images\_temp\imageUploa dTest.jpg

But maybe that path is malformed? Does it look correct?
Dim g as New System.Drawing.Image
g = System.Drawing.Image.FromFile(strTempFullFileName)


I tried that, but get an error in the IDE:

Dim g As New System.Drawing.Image

('new' cannot be used on a class that is declared 'MustInherit')

-Darrel
Feb 22 '06 #5

P: n/a
Ah, here we go. Image is an abstract class. try this

Dim g as New System.Drawing.Bitmap(strTempFullFileName)

Don't worry that it's a "Bitmap", that just means it deals with pixels.
You can call something like g.save("bla.jpg", ImageFormat.Jpeg) to
save jpg's and such.

HTH,
Darren Kopp
http://blog.secudocs.com/

Feb 22 '06 #6

P: n/a
Dim g as New System.Drawing.Bitmap(strTempFullFileName)


I was optimitic! The IDE does let me enter that, but, alas, I get the exact
same error when I try to execute it.

-Darrel
Feb 22 '06 #7

P: n/a
could you post the code for how you upload the image and where you
assign a value to strTempFullFileName? The more code to look at the
easier it will be to find out what's happening.

-Darren Kopp
http://blog.secudocs.com/

Feb 22 '06 #8

P: n/a
could you post the code for how you upload the image and where you
assign a value to strTempFullFileName? The more code to look at the
easier it will be to find out what's happening.


Sure, though, that part of the code does execute just fine. The image is
uploaded and is sitting in that particular folder:

----------------------------------------------------------------------
Dim postedFile = uploadedFile.PostedFile
Dim contentType As String = postedFile.ContentType
Dim contentLength As Integer = postedFile.ContentLength

strUploadFileName = Mid(postedFile.FileName, InStrRev(postedFile.FileName,
"\") + 1)

'clean up the filename
strUploadFileName = fixFileName(strUploadFileName)

'Temp file name/location
strTempFullFileName = savePath & "_temp\" & strUploadFileName

'save the temp file
postedFile.SaveAs(strTempFullFileName)

resizeImage(categoryFolder, customImageSize, "jpg", strUploadFileName)

----------------------------------------------------------------------

The file I am trying to retrieve does have the correct path and file name as
the string is resolving to.

-Darrel
Feb 22 '06 #9

P: n/a
Where do you declare strTempFullFileName? I don't see Dim
strTempFullFileName as String. That could be the cause of the
exception, but even with that i wouldn't think it would compile. Also
shouldn't it be...

Dim postedFile as HttpPostedFile = uploadedFile.PostedFile?

-Darren Kopp

Feb 22 '06 #10

P: n/a
> Where do you declare strTempFullFileName? I don't see Dim
strTempFullFileName as String. That could be the cause of the
exception, but even with that i wouldn't think it would compile. Also
shouldn't it be...


Darren:

Thanks for all the help. In the process of trying to send over the code, I
gave it yet another once over.

I think I discovered a user error on my part. One function was erroring out,
cascading back to the parent function, which then tried to execute a CAPTCH
statement, which, itself, had an error.

So, all this time, the error I was receiving wasn't referring to the actual
problem.

ARGH!

;o)

-Darrel
Feb 23 '06 #11

P: n/a
Hahaha, yea... I have felt the sting of those mistakes before too.
Glad to hear that you resolved the problem.

Happy .NETing,
Darren Kopp
http://blog.secudocs.com/

Feb 23 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.