FileUp.PostedFile == null

Discussion in 'ASP .Net Web Controls' started by Gary Wardell, Jul 23, 2008.

  1. Gary Wardell

    Gary Wardell Guest

    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, Jul 23, 2008
    #1
    1. Advertisements

  2. Gary Wardell

    Gary Wardell Guest

    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
     
    Gary Wardell, Jul 26, 2008
    #2
    1. Advertisements

  3. Gary Wardell

    gtes g Guest

    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
     
    gtes g, Nov 9, 2009
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.