用jQuery-File-Upload上传Excel文件(ASP.NET MVC)[附源码下载]
来源:互联网 发布:php留言板源码 编辑:程序博客网 时间:2024/04/29 08:08
MVC的cshtml部分:
@{ ViewBag.Title = "djk8888";}<script src="~/jQuery-File-Upload-8.8.5/js/jquery.min.js"></script><script src="~/jQuery-File-Upload-8.8.5/js/vendor/jquery.ui.widget.js"></script><script src="~/jQuery-File-Upload-8.8.5/js/jquery.iframe-transport.js"></script><script src="~/jQuery-File-Upload-8.8.5/js/jquery.fileupload.js"></script><script src="~/jQuery-File-Upload-8.8.5/js/jquery.fileupload-process.js"></script><script src="~/jQuery-File-Upload-8.8.5/js/jquery.fileupload-validate.js"></script><link href="~/jQuery-File-Upload-8.8.5/css/jquery.fileupload-ui.css" rel="stylesheet" /><style type="text/css"> .bar { height: 18px; background: green; }</style><script> $(function () { $('#fileupload').fileupload({ url: "/Home/UploadFiles", dataType: 'json', replaceFileInput: false,//显示已选择文件文件名(必须) progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); $('#progress .bar').css('width', progress + '%'); }, add: function (e, data) { //判断文件类型,此例限制为:Excel文件 var fileType = data.files[0].name.split('.').pop(); var acceptFileTypes = /xls|xlsx$/i; if (!acceptFileTypes.test(fileType)) { $("#startBtn").hide();//隐藏上传按钮 alert("不支持的文件类型,仅支持EXCEL文件"); return; } //判断文件大小,此例限制为:1mb: var size = data.files[0].size; size = (size / 1024).toFixed(2);//文件大小单位kb var maxFileSize = 1024;//1mb=1024kb if (size > maxFileSize) { $("#startBtn").hide();//隐藏上传按钮 alert("文件大小:" + size + "KB,超过最大限制:" + maxFileSize + "KB"); return; } $("#startBtn").show();//显示上传按钮 //点击上传按钮开始上传 data.context = $('#startBtn').click(function () { data.context = $('<p/>').text('Uploading...').replaceAll($(this)); data.submit(); }); }, done: function (e, data) { data.context = $('<p/>').text("文件上传成功!").replaceAll($(this)); }, change: function (e, data) { if (data.files.length > 1) { $("#startBtn").hide();//隐藏上传按钮 alert("只能选择1个文件"); return false; } }, drop: function (e, data) { if (data.files.length > 1) { $("#startBtn").hide();//隐藏上传按钮 alert("只能选择1个文件"); return false; } }, }); });</script><h2>用jQuery-File-Upload上传Excel文件(ASP.NET MVC)</h2><input id="fileupload" type="file" name="multiFiles" multiple /><button id="startBtn" style="display:none;">上传</button><div id="progress"> <div class="bar" style="width: 0%;"></div></div>ASP.NET MVC的Controller部分
using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;using System.Web.Mvc;namespace jqueryfileupload.Controllers{ public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] public ActionResult UploadFiles() { try { for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; var fullPath = Path.Combine(StorageRoot, Path.GetFileName(file.FileName)); file.SaveAs(fullPath); } return Content("上传成功!"); } catch (Exception ex) { return Content(ex.ToString() + "\r\n" + ex.Message + "\r\n" + ex.Source + "\r\n" + ex.StackTrace); } } private string StorageRoot { get { return Path.Combine(Server.MapPath("~/Files")); } } }}
配套源代码下载地址:
http://download.csdn.net/download/djk8888/10163404
http://download.csdn.net/download/djk8888/10167119 [推荐]
吐槽一下:我就是想让大家0分下载,但是现在CSDN的下载积分规则变了,我也只好呵呵了
用easyui-filebox上传Excel文件(ASP.NET MVC) 传送门:http://blog.csdn.net/djk8888/article/details/78859688
阅读全文
0 0
- 用jQuery-File-Upload上传Excel文件(ASP.NET MVC)[附源码下载]
- 用easyui-filebox上传Excel文件(ASP.NET MVC)[附源码下载]
- Asp.Net Mvc 带进度条大文件上传(附源码下载)
- .net文件上传,客户端用jquery file upload
- 在ASP.NET中实现多文件上传(三)---jQuery Multiple File Upload Plugin
- jQuery Ajax File Upload(附源码)
- jQuery Ajax File Upload(附源码)
- Spring MVC 文件上传 file upload
- JQuery Upload File 上传文件提示 Empty file upload result
- jquery-file-upload 文件上传,带进度条
- jQuery-File-Upload 文件上传插件
- asp.net+swfupload 多图片批量上传(附源码下载)
- 【Spring】Spring MVC文件上传--整合bootstrap-fileinput和jQuery-File-Upload
- 利用jQuery-file-upload在MVC中实现上传文件(未完成)
- 【文件上传->jQuery-File-Upload】jQuery-File-Upload图片上传组件简要使用指南(挥泪共享)
- ie8下使用jquery-file-upload上传文件后返回json格式数据提示下载
- asp.net mvc动态生成file控件批量上传文件
- asp.net mvc动态生成file控件批量上传文件 .
- hibernate.cfg.xml 配置
- RxJava介绍
- 003
- spring-boot动态添加、删除定时任务
- Python网络数据采集
- 用jQuery-File-Upload上传Excel文件(ASP.NET MVC)[附源码下载]
- Hive 解决 comment 中文乱码
- js图表调研文档
- freemarker的基本标签的使用与el表达式比较
- Java 得到当前系统时间,时间转字符串,字符串转时间,以及求时间差
- Java读写docx文档(读取内容并替换其中的关键字)
- Unity ColorMask 对应值
- unity项目去除unity开始动画和发布设置
- Egret移动网络音频加载问题