How to Persist HtmlInputFile Value through postback?

D

Dave Adler

Is there any way to retain the value of an HtmlInputFile control through a
postback?

I do some server side validation on the page when it is submitted and if an
error occurs on the page the HtmlInputFile control value is blank after the
postback. The EnableViewState for the control is set to true. I can't put
the postedFile.filename value in a hidden control and then put it back into
the HtmlInputFile control on postback because the postedFile.filename and
the value properties are read-only.

Any ideas?

Thanks in advance

David
 
C

CJ Taylor

HtmlInputFile does a lot more than just a "textbox" which is why its read
only.

You have to save that file and then use a label at that point, otherwise
your just wasting bandwidth.

2) You don't know the name of the file on the users end do you? Of course
you don't, just the file name, not the dirs or anything.
 
D

Dave Adler

Well here is the deal. I have multiple HtmlInputFile controls on a single
form. I also have other input controls on the form. In my validation
routine, I check to see if the user checked a checkbox control to overwrite
existing files. If it is not checked, I verify that the filenames of the
files the user elected to upload are not the same as files in the upload
directory. If they are the same, I put a descriptive error message on the
page that identifies which file is exsiting and what action to take.
However, since the HtmlInputFile control does not retain its selected file
during postback, the user has to reselect all of the files he wants to
upload in order to to resubmit the form.

I was hoping that I could use the multiple file upload approach as opposed
to a single upload but this issue removes any advantage if the user has to
reselect multiple files each time there is a postback.

Thanks for your feedback though.

David
 
C

CJ Taylor

Whats to say that you have to do it all in one "shebang" like this.

If the user uploads the files, and some exist, no one said you have to save
it in that directory right at that moment. You can place them in a temp
directory, send the filenames back on the postback (not requiring to be
resubmitted) and then give the user the option to do whatever they want with
those files with like checkboxes or some other control.

Then on each consectutive postback, you don't have any files to transfer
because they are already server side, making your post backs faster, less
hassle on you users, and a more effecient web program.

HTH,
CJ

"You know how I know I'm nerd? Most people have trophies, I have a
USRobotics Courier external modem on my mantle." -CJ Taylor
 

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

Ask a Question

Top