FileUp.PostedFile == null

G

Gary Wardell

Hi,

If HasFile is true, why is PostedFile "sometimes" == null in my tests?

That is, if I resubmit the form with the same data it's not null, and may be
repeatedly not null. But then it will occasionally be null again, for one
or two submits. It seems to be random.

What's going on here?

This is using ASP.net 2.0 SP 1.

Gary

private FileUpload FileUp;
FileUp = (FileUpload)Pnl.FindControl("FileUp");
if (!FileUp.HasFile)
{
if (FileUp.PostedFile == null) throw new
NullReferenceException("PostedFile is Null");
if (FileUp.PostedFile.ContentLength == 0)
{
MJOStaff.SetMsg("The file is either missing or empty",
MJOStaff.msgType.Warning);
return;
}
}
 
G

Gary Wardell

Hi,

I finally found my problem.

ASP was not setting the form encoding, even though there was an asp upload
control on the page.

What made this a bit hard to track down was that it only intermittently
failed.

I explicitly set the encoding and now it seems to work all of the time, like
it should.

Gary
 
G

gtes g

Hi,
I am having a similar issue in a usercontrol. I am using the fileupload control in a user control called DocList and have this user control inside another user control.
Could you please let me know the code-fix that you had for similar issue.

Thanks a bunch!



Gary Wardell wrote:

Hi,I finally found my problem.
26-Jul-08

Hi

I finally found my problem

ASP was not setting the form encoding, even though there was an asp uploa
control on the page

What made this a bit hard to track down was that it only intermittentl
failed

I explicitly set the encoding and now it seems to work all of the time, lik
it should

Gary

Previous Posts In This Thread:

FileUp.PostedFile == null
Hi

If HasFile is true, why is PostedFile "sometimes" == null in my tests

That is, if I resubmit the form with the same data it's not null, and may b
repeatedly not null. But then it will occasionally be null again, for on
or two submits. It seems to be random

What's going on here

This is using ASP.net 2.0 SP 1

Gar

private FileUpload FileUp
FileUp = (FileUpload)Pnl.FindControl("FileUp")
if (!FileUp.HasFile

if (FileUp.PostedFile == null) throw ne
NullReferenceException("PostedFile is Null")
if (FileUp.PostedFile.ContentLength == 0

MJOStaff.SetMsg("The file is either missing or empty"
MJOStaff.msgType.Warning)
return

}

Hi,I finally found my problem.
Hi

I finally found my problem

ASP was not setting the form encoding, even though there was an asp uploa
control on the page

What made this a bit hard to track down was that it only intermittentl
failed

I explicitly set the encoding and now it seems to work all of the time, lik
it should

Gary

EggHeadCafe - Software Developer Portal of Choice
11 Ways to use JavaScript efficiently
http://www.eggheadcafe.com/tutorial...6-d98c3ffbc098/11-ways-to-use-javascript.aspx
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top