ajax传输,后台同步,后台json传输,文件,文件夹复制删除,查询,新建,在线压缩
来源:互联网 发布:mac os sierra升级 编辑:程序博客网 时间:2024/05/12 19:41
先贴出来 ajax代码
function outto() { $("#showxz").hide() if ($("#ids").attr("value") == "") { alert('未选中任何数据'); return; } var a = $("#ids").attr("value"); var t = a.split(','); //都完成了才可以显示下载文件名 if (confirm("您要操作的数据条数为 " + t.length + ",确认后继续?") == true) { $("#ssj").val('......系统正在压缩中请稍后.....'); setTimeout(function () { $.ajax({ type: "GET", url: "/xxhz_admin/filemore/", //temp:预防360缓存内容,保存iis的sessionID data: { ids: a, temp: Math.random() }, async: true,//异步之后不影响本页其他功能 dataType: "json", success: function (data) { if (data.name == '') { $("#ssj").val('......压缩完成.....'); $("#showxz").show(); } // alert(data.ret); //alert(data); }, error: function (XMLHttpRequest, textStatus, errorThrown) { //alert(XMLHttpRequest.status); //alert(XMLHttpRequest.readyState); //alert(textStatus); } }); }, 1000); } }
页面中
<input type="text" id="ssj" name="ssj" style="width:200px;" />
<div id="showxz" style="display:none; float:right; width:400px;">
<a href="/temprar/1.rar" target="_blank">【 下载文件1 】</a>
</div>
后台代码,包含,目录操作和文件的操作,还有压缩,注意WinRAR程序所在的位置
public JsonResult filemore(string ids) { string ttt_rpath = Server.MapPath("/temprar/yuan1"); // string s_rpath="D:\\Web\\weixin\\upload\\"; List<string> str = new List<string>(); string nstr = ""; string s_rpath = "E:\\CASE\\文化表彰投票\\修改\\weixin\\upload\\"; string errstr = "",ret="0";//空就是没有错误, List<string> ids_array = ids.Split(',').ToList<string>(); var list = from a in base_db.SB_XMGL where (ids_array).Contains(a.ID.ToString()) select a; var res = new JsonResult(); //1查找文件是否在 foreach (var item in list) { nstr = s_rpath+"\\"+item.SB_PC_ID+"\\"+item.SB_order+"\\"+item.SB_NAME + ".doc"; str.Add(nstr); if (!string.IsNullOrEmpty(item.IMG1)) { string[] ab = item.IMG1.Split(','); for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Protocol\\" + ab[i]; str.Add(nstr); } } if (!string.IsNullOrEmpty(item.IMG2)) { string[] ab = item.IMG2.Split(','); for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Implementation\\" + ab[i]; str.Add(nstr); } } if (!string.IsNullOrEmpty(item.IMG3)) { string[] ab = item.IMG3.Split(','); for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Outcome\\" + ab[i]; str.Add(nstr); } } if (!string.IsNullOrEmpty(item.IMG4)) { string[] ab = item.IMG4.Split(','); for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Supplement\\" + ab[i]; str.Add(nstr); } } } foreach (string item in str) { if(!System.IO.File.Exists(item)) { errstr = "丢失文件:" + item; } } if (errstr == "") { string savePath = ttt_rpath+"";//获得当前的文件目录 //删目录下所有文件 DirectoryInfo dir = new DirectoryInfo(savePath); FileSystemInfo[] fileinfo = dir.GetFileSystemInfos(); //返回目录中所有文件和子目录 foreach (FileSystemInfo i in fileinfo) { if (i is DirectoryInfo) //判断是否文件夹 { DirectoryInfo subdir = new DirectoryInfo(i.FullName); subdir.Delete(true); //删除子目录和文件 } else { System.IO.File.Delete(i.FullName); //删除指定文件 } } foreach (var item in list) { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\" + item.SB_NAME + ".doc"; System.IO.File.Copy(nstr, savePath + "\\" + item.SB_NAME + ".doc", true); if (!string.IsNullOrEmpty(item.IMG1)) { string[] ab = item.IMG1.Split(','); if (!Directory.Exists(savePath + "\\" + item.SB_order + "\\Protocol\\")) { Directory.CreateDirectory(savePath + "\\" + item.SB_order + "\\Protocol\\"); } for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Protocol\\" + ab[i]; System.IO.File.Copy(nstr, savePath + "\\" + item.SB_order + "\\Protocol\\" + ab[i], true); } } if (!string.IsNullOrEmpty(item.IMG2)) { string[] ab = item.IMG2.Split(','); if (!Directory.Exists(savePath + "\\" + item.SB_order + "\\Implementation\\")) { Directory.CreateDirectory(savePath + "\\" + item.SB_order + "\\Implementation\\"); } for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Implementation\\" + ab[i]; System.IO.File.Copy(nstr, savePath + "\\" + item.SB_order + "\\Implementation\\" + ab[i], true); } } if (!string.IsNullOrEmpty(item.IMG3)) { string[] ab = item.IMG3.Split(','); if (!Directory.Exists(savePath + "\\" + item.SB_order + "\\Outcome\\")) { Directory.CreateDirectory(savePath + "\\" + item.SB_order + "\\Outcome\\"); } for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Outcome\\" + ab[i]; System.IO.File.Copy(nstr, savePath + "\\" + item.SB_order + "\\Outcome\\" + ab[i], true); } } if (!string.IsNullOrEmpty(item.IMG4)) { string[] ab = item.IMG4.Split(','); if (!Directory.Exists(savePath + "\\" + item.SB_order + "\\Supplement\\")) { Directory.CreateDirectory(savePath + "\\" + item.SB_order + "\\Supplement\\"); } for (int i = 0; i < ab.Length; i++) { nstr = s_rpath + "\\" + item.SB_PC_ID + "\\" + item.SB_order + "\\Supplement\\" + ab[i]; System.IO.File.Copy(nstr, savePath + "\\" + item.SB_order + "\\Supplement\\" + ab[i], true); } } } } //2复制文件 //3压缩文件 string ttt_rpath = Server.MapPath("/temprar/yuan1"); //开始压缩 if (errstr == "") { ProcessStartInfo startinfo = new ProcessStartInfo(); ; Process process = new Process(); string rarName = "1.rar"; //压缩后文件名 string path = ttt_rpath; //待压缩打包文件夹 string rarPath = Server.MapPath("/temprar"); //压缩后存放文件夹 string rarexe = @"E:\CASE\文化表彰投票\修改\winrar360\WinRAR.exe"; //WinRAR安装位置 string cmd = string.Format("a {0} {1} -r", rarName, path); startinfo.FileName = rarexe; startinfo.Arguments = cmd; //设置命令参数 startinfo.WindowStyle = ProcessWindowStyle.Hidden; //隐藏 WinRAR 窗口 startinfo.WorkingDirectory = rarPath; process.StartInfo = startinfo; process.Start(); process.WaitForExit(); //无限期等待进程 winrar.exe 退出 if (process.HasExited) { ret = "1";//代表压缩成功 } } var datae = //new filemore(); //var q = from a in ty // select new new { ret = ret, name = errstr }; res.Data = datae; res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;//允许使用GET方式获取,否则用GET获取是会报错。 return res; }
阅读全文
0 0
- ajax传输,后台同步,后台json传输,文件,文件夹复制删除,查询,新建,在线压缩
- ajax传输json到后台
- 使用Ajax中的Json传输数据时,从后台查询的字段过滤方法。
- ajax 前台后台传输数据
- FTP 传输文件后台代码
- Linux后台传输screen
- 蓝牙后台传输数据
- 解决后台传输list到前台以json格式
- 关于Ajax调用时后台数据的传输问题
- Ajax传输JSON
- 分布式架构项目中各模块中页面发送ajax请求后台json数据的传输问题
- base64后台传输细节处理
- 在前后台传输时间数据
- Ajax同步传输和异步传输
- 一个从后台直接传输到后台的jquery easyui 的json页面
- ssh 用 scp 命令 后台传输文件 ,不需要输入密码
- 用scp后台传输文件,用rsync进行断点续传
- iOS进入后台后长时间传输多个文件…
- C/C++ 第八周串和数组 (一)对称矩阵压缩存储的实现与应用 项目3—(2)
- java使用CsvReader和CsvWriter对csv文件内容进行读取和写入操作
- finally
- [找规律] SRM599 500-point FindPolygons
- PyQt5简单小工具制作步骤:
- ajax传输,后台同步,后台json传输,文件,文件夹复制删除,查询,新建,在线压缩
- 在gradle中使用MyBatis Generator生成model,dao,mapper
- 关于GPRS模块支持MQTT的选择
- UML 用例图
- Java语法糖系列之枚举类型
- jquery.superslide 参数分析
- Nginx集群之基于Redis的WebApi身份验证
- Dubbo 学习
- 非[无]root权限 服务器 下安装perl以及perl模块