Title: How to upload a file to server?
Tags: javascript;jquery;asp.net-mvc-3
Question: I am using Upload File control in MVC-3 project,
<input type="file" name="file" /&gt;
Is there any way Or is it possible to manually (programatically) assign the file to this input control? something like,
$('input[type=file]').val("filename or address or somethingelse" )?
Comment: Nope, it's not possible.

Comment: @DarinDimitrov thanks a lot for explaining me this much clearly and you are absolutely right this not possible :)

Comment: Just imagine if that was possible. What would prevent you from doing this: `$('input[type=file]').val('c:\\documents\\mycreditcards.txt');` and then using AJAX to upload the file to your server without the client ever knowing what is going on? Well, actually he will understand what's going on a bit later when he receives a couple of letters from his bank.

Here is the accepted answer: AFAIK you cannot select/assign a file via JS for security reasons. Otherwise you could enter website that automatically selects some sensitive data file from your PC and automatically upload it on server.
You can, however select file manually and upload it automatically via JS after selecting it.

Here is another answer: You can not do because of security reasons

Here is another answer: No, this is not possible due to security issues.
What you can do is to use some kind of uploader, i.e. http://valums.com/ajax-upload/

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:07/13/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><jquery><asp.net-mvc-3>', 'Title': 'How to upload a file to server?', 'ViewCount': 284, 'id': 11467303, 'user_AboutMe': None, 'user_AccountId': 1571416.0, 'user_DisplayName': 'Tom Rider', 'user_Reputation': 2627.0, 'user_Views': 298.0, 'user_id': 1459031.0}}