SitePoint Sponsor |
|
User Tag List
Results 1 to 20 of 20
-
Oct 20, 2006, 00:22 #1
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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
-
Oct 20, 2006, 01:27 #2
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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
-
Oct 20, 2006, 06:45 #3
- Join Date
- May 2003
- Location
- Washington, DC
- Posts
- 10,653
- Mentioned
- 4 Post(s)
- Tagged
- 0 Thread(s)
Is the form enctype set correctly?
-
Oct 23, 2006, 02:20 #4
- 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
-
Oct 23, 2006, 03:59 #5
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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?
-
Oct 23, 2006, 04:19 #6
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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?
-
Oct 23, 2006, 04:25 #7
- Join Date
- May 2003
- Location
- Washington, DC
- Posts
- 10,653
- Mentioned
- 4 Post(s)
- Tagged
- 0 Thread(s)
Not encryption, encoding type. Needs to be multipart/form-data.
-
Oct 23, 2006, 04:35 #8
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 Post(s)
- Tagged
- 0 Thread(s)
Hey wwb.
Where do I set the encoding?
-
Oct 23, 2006, 04:37 #9
- Join Date
- May 2003
- Location
- Washington, DC
- Posts
- 10,653
- Mentioned
- 4 Post(s)
- Tagged
- 0 Thread(s)
In the form tag on your MasterPage.
-
Oct 23, 2006, 04:39 #10
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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
-
Oct 24, 2006, 05:53 #11
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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
-
Oct 24, 2006, 05:57 #12
- 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
-
Oct 24, 2006, 06:10 #13
- 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...
-
Oct 24, 2006, 06:51 #14
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 Post(s)
- Tagged
- 0 Thread(s)
. Stupid Atlas. hehehe
-
Oct 24, 2006, 07:33 #15
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
This might be of use: https://secure.codeproject.com/aspnet/FlashUpload.asp
-
Oct 24, 2006, 08:05 #16
- Join Date
- May 2003
- Location
- Washington, DC
- Posts
- 10,653
- 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.
-
Oct 24, 2006, 08:23 #17
- 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...
-
Oct 24, 2006, 10:28 #18
- Join Date
- May 2003
- Location
- Washington, DC
- Posts
- 10,653
- Mentioned
- 4 Post(s)
- Tagged
- 0 Thread(s)
Yeah, I guess I did not quite recall correctly.
-
Oct 24, 2006, 11:47 #19
- 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...
-
Oct 25, 2006, 00:09 #20
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 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