views:

312

answers:

2

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.

+2  A: 

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

Jørn Schou-Rode
A: 

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

Nasser Hadjloo