Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FileUp.PostedFile == null

85 views
Skip to first unread message

Gary Wardell

unread,
Jul 23, 2008, 6:28:48 AM7/23/08
to
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;
}
}

Gary Wardell

unread,
Jul 26, 2008, 3:16:12 PM7/26/08
to
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


gtesg

unread,
Nov 9, 2009, 6:01:46 PM11/9/09
to
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,

Gary

Previous Posts In This Thread:

On Wednesday, July 23, 2008 6:28 AM
Gary Wardell wrote:

FileUp.PostedFile == null
Hi,

Gary

On Saturday, July 26, 2008 3:16 PM
Gary Wardell wrote:

Hi,I finally found my problem.
Hi,

Gary

EggHeadCafe - Software Developer Portal of Choice
11 Ways to use JavaScript efficiently
http://www.eggheadcafe.com/tutorials/aspnet/60a4a785-5349-43ba-bc76-d98c3ffbc098/11-ways-to-use-javascript.aspx

0 new messages