开发者

UploadFile Control loses it's data on PostBacks?

What's wrong! .. seems like it's a common issue .. and even if I try to persist it's value I can only keep it in anywhere like a hiddenfield but looks like there's no pro开发者_JAVA技巧perty that saves the whole location of the file on the local machine and even if I got it, I can't assign the value back to the FileUpload because all of it's properties are ReadOnly!

Any simple solutions please !?


this is by design - file upload is readonly because otherwise it would be a huge security risk... see http://www.w3.org/TR/html4/interact/forms.html#file-select

depending on what functionality you are trying to implement there could be other possible solutions... please elaborate.


Imagine if you can set that field programatically; what would stop a malicious developer from populating that field and accessing the user's files?

short answer is that every postback will require the user to select the file again for upload. If the postback occurs, it means the file is bad, so the user should be selecting another file anyway.

If the postback occurs because the user entered incorrect metadata for the file, while the file itself is fine, then you can just cache the file name and display it for the user again. Just put a fake, read-only textbox on top of the actual file upload textbox and display the file name back to the user. The file should have already been uploaded to the web server so no upload is necessary (i.e. the real file upload textbox can remain blank)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜