简体   繁体   中英

How to set the value dynamically to a asp.net file upload control?

I have a fileupload control.I'm selecting a image using the control and saving it in the database.In the edit mode,I need to assign the path of the image in the textbox of the file upload control.Is it possible ?? If so,how could I achieve it??

Regards, Srinivas.

No, it is not possible to set an initial value for a <input type="file" /> element. The reason for this constraint (which is enforced by the browser, not by ASP.NET) is security. Consider the consequences of a malicious website owner placing the following in a form:

<input type="file" value="c:\\bank\\secret.key" />

However, I am not sure that this limitation is really a problem in the scenario you are describing. Having the <input type="file"> prefilled with the path to the image file on the server , is unlikely to help anyway, as the value selected in a file field is used to point to a file on the client , which will be uploaded as part of the form postback.

Instead, consider constructing your edit form in a way where the current image is displayed (possibly as a thumbnail) along with an <input type="file"> field for uploading a new image to overwrite the existing, and a checkbox allowing the user to remove the current image (if this action is allowed).

It is meaningless to set a file which located on a client, from a server. it is like a jailbreaking or some kind of injection

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM