views:

42

answers:

1

This one has got me stumped. I am currently rendering a form using ASP MVC, it has a bunch of fields, one of them is an <input type="file"...

The file upload works great, but when I return the form to the user, the textbox that contains the file is empty. I would like to show the filepath in the textbox, but it appears the value field does not populate this textbox.

Ie. <input type="file" value="abc.txt" /> does not put "abc.txt" into the textbox.

How can I populate the textbox of an HTML file input? Is there another property that I should be using other than the value property?

Any help would be much appreciated,

+3  A: 

That textbox is readonly and you can't explicitly set the value of it.

amurra
+1, and the reason it is readonly is because if you *could* set it, then you could set it to any file on the file system. If the browser subsequently actually allowed that file to upload, you would have a gross security issue.
Kirk Woll
+1 for answering the question (as opposed to my mis-reading of it *cough* ), with thanks @Kirk
David Thomas
@Kirk - You are exactly right with the reason it is readonly. Now you can use jQuery to clear the contents of that textbox, but anything else would definitely be a huge security issue.
amurra
Thanks guys, I guess I could indicate the file in free text beside the textbox, your explanation makes total sense. It's too bad since I'm indicating a file that they have already uploaded, but the best security solution was to make the textbox read-only, no exceptions.
Mark Kadlec