前台代码:
<form action="/User/ImpExcel" method="post" enctype="multipart/form-data" >
<span class="uploadBtn small">
<input type="file" id="upFiles" name="upFiles"><span>上传文件</span>
</span>
<span class="ftips">(上传前,请关闭文件。)</span>
<input type="submit" value="确认上传" class="btn-sure" id="Btn_submit">
</form>
后台代码:
public ActionResult ImpExcel(string str)
{
int iRusult = 0;
if (Request.Files["upFiles"] != null) // If uploaded synchronously
{
//判断文件大小
if (Request.Files["upFiles"].ContentLength < 1024 * 1024 *10)
{
//判断文件类型
string strType = Request.Files["upFiles"].ContentType;
string fileType= Path.GetExtension(Request.Files["upFiles"].FileName).ToUpper();
// if (strType == "application/vnd.ms-excel" || strType == "application/kset")
if (fileType == ".XLS")
{
//上传文件
string photo_guid = _fileStore.SaveUploadedFile(Request.Files["upFiles"]);
}
}
}
}