ASP.NET FileUpload doesn’t work

So you added a FileUpload control in order to receive files from your clients. The problem? HasFile() returns false every time you send a file.

Reason of this problem is described in HTML specification. Basically, if the forms sent by your page will contain file data, multipart/form-data should be used.

To use it in ASP.NET we just need to specify following line in our code:

Page.Form.EncType = "multipart/form-data"

I am not 100% sure but I haven’t heard about a rule that forces you to use the above code in load, init, prerender or any other place. If you know more about this, feel free to write a comment.


Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: