I used this:
$(\'input[type=file]\').val()
to get the file name selected, but it returned the full path, as in \"C:\\fakepath\\filename.doc
var filename = $('input[type=file]').val().split('\\').pop();
or you could just do (because it's always C:\fakepath
that is added for security reasons):
var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '')
Get the first file from the control and then get the name of the file, it will ignore the file path on Chrome, and also will make correction of path for IE browsers. On saving the file, you have to use System.io.Path.GetFileName
method to get the file name only for IE browsers
var fileUpload = $("#ContentPlaceHolder1_FileUpload_mediaFile").get(0);
var files = fileUpload.files;
var mediafilename = "";
for (var i = 0; i < files.length; i++) {
mediafilename = files[i].name;
}