Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent FileUpload control from clearing on postback?

I'm having some trouble with the FileUpload control and was wondering if I could get some help.

On my page I have a FileUpload control, and a drop down list.

So the user browses to the file they want, and then select an option from the drop down (which enables some checkboxes that are also on the page for use, depending on what they select in the drop down). This causes the FileUpload control to become empty, and now the user must browse to the file they wanted again.

Is there anyway to prevent the FileUpload control from losing its contents during the PostBack?

like image 477
Denis Sadowski Avatar asked Jul 10 '09 19:07

Denis Sadowski


1 Answers

Since you tried Relster's suggestion and it didn't work, Spencer is correct. Due to security concerns, it is impossible for anything but the browser to set the path in an <input type="file"/> element. The only solution is to restructure the flow so that the only postback is done when you want to submit the file, and do any other manipulation with client side scripting.

The reason you cannot set the path is because it would allow you to steal users' files. For example, if you hide the input, and have an innocent looking button for postback, you could set the default path of the file input to whatever you wanted to get access to, and the user would upload it without ever knowing what's going on.

like image 171
Sean Avatar answered Oct 23 '22 04:10

Sean