HtmlInputFile and FileUpload
The two controls listed above provide mechanisms to upload files to the
web server. With the 2.0 framework, the FileUpload is a server control
equivalent to the HtmlInputFile, and provides some additional
enhancements to the control. It adds a HasFile property stating if a
file has been selected in the upload box, as well as additional file
accessing properties directly in the control, instead of referencing
PostedFile. I did notice one quirk; the FileName property in FileUpload
only contains the name of the file; the FileName property in the
PostedFile property contains the entire path.
One other point;
these controls do not save their viewstate. LoadPostData always returns
false, and the Value property is readonly. You can inherit from the
class and override LoadPostData to return true and try to restore the
value, but value is readonly. I did read about that it may be possible
to set the value through javascript, but in all my attempts, I failed,
so I gave up on it.
If you want to create one to restore viewstate, you have to look at that as an option.
Here is a
multiple file upload control
that I created, which renders multiple upload boxes so a user can
upload in bulk. The only problem is this control does not retain its
state across postbacks, and as such, you have to create the number of
boxes you want first before you browse to the files.