SitePoint Sponsor

User Tag List

Results 1 to 20 of 20
  1. #1
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)

    Checking if a user uploaded a file

    Hey guys

    Im fairly new to asp.net 2.0, but i know asp.net 1.1 pretty well. This is my question:

    I have an <asp:FileUpload> control for a user to upload a file.

    But now b4 i run the upload code, i wana check if the user did select a file or not:

    if (file.PostedFile.FileName != "")
    {
    //upload code
    }

    Thats wat id do in 1.1, but in 2.0 it gives me the object ref not set to an instance of an object error.

    I aslo tried this:

    if (file.PostedFile != null)
    {

    }

    then it doesnt give me errors, but never runs the code. Any ideas?

    Thanks

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    I dnt no wat is going on with this thing.

    It also gives me "Object Reference not set to and instance of an object" wen I do this:

    string filesName = file.PostedFile.FileName;


    And is does the same thing whether I use the asp server side control or the <input type="file"> html control.

    Anything I can check to sort this problem out?

    Thanks

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Is the form enctype set correctly?

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or there is the .HasFile property, which might help a little

    http://msdn2.microsoft.com/en-us/lib...d.hasfile.aspx

  5. #5
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    Hey. Thanks for the replies.

    @ wwb. I have not set the form encryption as i dnt think its important using the asp:FileUpload control and I never used it b4 and it still worked fine.

    @dhtml god. I used this: bool fileName = file.HasFile;

    then i put a break point in and step thru the code. Its still coming back as false no matter if I upload a file or not.

    Any ideas why its doing that?

  6. #6
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    Has it maybe got something to do with the fact that the <form> tag is in the master page and the FileUpload controls or on a content page?

  7. #7
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Not encryption, encoding type. Needs to be multipart/form-data.

  8. #8
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    Hey wwb.

    Where do I set the encoding?

  9. #9
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    In the form tag on your MasterPage.

  10. #10
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    This is how the form looks on the master page:

    <form runat="server" id="Form1" name="Form1" enctype="multipart/form-data">

    Is there anything wrong with it?

    Thanks for all the help guys

  11. #11
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    Hey guys.

    I found the problem! Its coz it was in an atlas update panel. As soon as I took it out the update panel, it worked fine.

    Is there a was to get around this? Coz I need to put it in an update panel.

    Any ideas?

    Thanks

  12. #12
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh dear... I'm wanting to have a file upload in an update panel... I'll have a little look at it and tell you how I get on. Have you got the latest releases? All the links and a lovely post by our endearing .NET blogger can be found here: http://www.sitepoint.com/blogs/2006/...ta-1-released/


    Off Topic:

    There you go Wyatt, no need for some self promotion :P

  13. #13
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It appears that it isn't possible to do a file upload with "Atlas" and the UpdatePanel...

  14. #14
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    . Stupid Atlas. hehehe

  15. #15
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  16. #16
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    IIRC, there is a file upload widget in the atlas control toolkit. That might work for you.

  17. #17
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I can see, there isn't one http://ajax.asp.net/default.aspx?tabid=47&subtabid=477 unless I'm overlooking something...

  18. #18
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I guess I did not quite recall correctly.

  19. #19
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn Guess I'll have a little peck at the Extender projects and see if I can write one...

  20. #20
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,869
    Mentioned
    38 Post(s)
    Tagged
    0 Thread(s)
    That is a pitty about this upload thing. dhtmlgod. If u manage to write one.... plz send it to me. .

    ill also look into that flash uploaded.

    Thanks for all the help guys.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •