SREENIVAS
SREENIVAS

Reputation: 31

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.

Upvotes: 3

Views: 11636

Answers (2)

Nasser Hadjloo
Nasser Hadjloo

Reputation: 12630

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

Upvotes: 0

Jørn Schou-Rode
Jørn Schou-Rode

Reputation: 38406

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).

Upvotes: 5

Related Questions