Request.Files["file2"].FileName
IE启动时,取得的是文件的全路径,谷歌启动时,取得的是文件的单文件名
以后处理这类问题时,需要多浏览器debug.
另:记录一下代码,需求就是去除默认上传文件控件的外形,只留一个按钮,同时后面文本框显示当前文件名.
<tr>
<td>
<span class="inputfile">文件选择
<input type="file" id="file1" name="file1" value="file1" οnchange="setFileName('file1','fileNameTextBox1')" />
</span>
</td>
<td>①</td>
<td>@Html.TextBoxFor(m => m.UploadFileName1, new { style = "width: 400px; text-align: left", id = "fileNameTextBox1" })</td>
<td><input type="submit" value="上传" name="File1Upload" style="width: 100px;" @Model.DisableEvidenceButton() /></td>
<td><input type="button" id="dlFile1" value="DL" title="DL" style="width: 50px;" οnclick="parent.location='@Url.Action("EvidenceDownload", "WorkFlowConfirmPortal", new { ApplyId = Model.ApplyId, CustomerID = Model.CustomerID, IsApprovalMode = Model.IsApprovalMode, IsFromReadAllPage = Model.IsFromReadAllPage, FolderName = "1" }) '" /><td>
<td><input type="button" id="deleteFile1" value="删除" title="删除" style="width: 50px;" @Model.DisableEvidenceButton() οnclick="parent.location='@Url.Action("EvidenceDelete", "WorkFlowConfirmPortal", new { ApplyId = Model.ApplyId, CustomerID = Model.CustomerID, IsApprovalMode = Model.IsApprovalMode, IsFromReadAllPage = Model.IsFromReadAllPage, FolderName = "1" }) '" /><td>
</tr>
JS:
function setFileName(fileId, fileNameText)
{
var file = $('#' + fileId).val().split('\\');
var fileName = file[file.length - 1];
$('#' + fileNameText).val(fileName);
}
css
.inputfile {
position: relative;
display: inline-block;
background: #F0F0F0;
border: 1px solid #6C6C6C;
border-radius: 4px;
padding: 4px 16px;
overflow: hidden;
color: #272727;
text-decoration: none;
text-indent: 0;
line-height: 12px;
margin-top: 3px;
}
.inputfile input {
position: absolute;
font-size: 100px;
right: 0;
top: 0;
opacity: 0;
filter: alpha(opacity=0);
}
.inputfile:hover {
background: #F0F0F0;
border-color: #6C6C6C;
color: #272727;
text-decoration: none;
}