HtmlInputFile during postback..

N

newmem

Hi

In the webform, if a use selects a file to upload and submits the form. But
if page validation fails, the HtmlInputFile loses the filename string and
the user has to re-select the file using the browse button.

Is there any way to persist the postedFile.filename during postback?

Appreciate any help.
 
B

Brock Allen

The value in a <input type=file> is not allowed to be set by the page. The
browser always sets it to blank by default. This is for security, as malicious
websites could seed the control with a path to sensitive data on your machine.
 
A

Alex

If you are having trouble with retrieving the name of the posted file, or
the location to the posted file, make sure the form in which this control
exists has the enctype="multipart/form-data" as seen below.

<form id="DefaultForm" method="post" runat="server"
enctype="multipart/form-data">
</form>

When you upload your picture, you should be able to access it in your code
behind like this.

HttpPostedFile file = Request.Files["MyFileUpload"];

where the control is <INPUT name="MyFileUpload">

Hopefully I answered the right question for you.
 
N

newmem

Can I use client-side validation ? would the browser retain the value in the
<input type=file> control?
 
B

Brock Allen

I've not tried too hard to make this work, but I don't even think client
side script allows you to set the value of the file input. Again, it's a
security risk, so hopefully this won't work for you. Sorry. ;)
 

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

Similar Threads

How to Persist HtmlInputFile Value through postback? 3
htmlInputFile 1
HtmlInputFile 1
using the HtmlInputFile 1
HTMLInputFile control... 2
htmlInputFile 2
HtmlInputFile control problem 1
HTMLInputFile Issue 3

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top