利用DotNetZip做了个多文件打包下载电子期刊并在本地可以正常使用电子期刊

思路:找到所有电子期刊需要的资料加入压缩包,拼接HTML代码生成电子期刊本地浏览需要的HTML文件加入压缩包,压缩提供下载

 

浏览电子期刊的HTML+jQuery代码,

 

<html xmlns="http://www.w3.org/1999/xhtml" ><head><meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-language" content="zh-CN" /> <meta name="robots" content="index,follow" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta name="rating" content="general" /> <meta name="author" content="" /> <meta name="copyright" content="" /> <meta name="generator" content="" /> <title>古镇慈城42期</title> <mce:style type="text/css"><!-- body {TEXT-ALIGN: center;margin: 0px;background-color: #b8c6aa;font-size: 12px;color: #4c4c4c;line-height: 20px;font-family: "宋体";height: 100%;padding:0px; margin:0px; padding-top:40px; background-image:url(images/bg.jpg); text-align:center;}img {border: 0px;}p {margin-bottom: 8px;margin-top: 0px;}.main{ text-align:center; width:1000px; margin-left:auto; margin-right:auto;}p{text-align:center;} --></mce:style><style type="text/css" mce_bogus="1">body {TEXT-ALIGN: center;margin: 0px;background-color: #b8c6aa;font-size: 12px;color: #4c4c4c;line-height: 20px;font-family: "宋体";height: 100%;padding:0px; margin:0px; padding-top:40px; background-image:url(images/bg.jpg); text-align:center;}img {border: 0px;}p {margin-bottom: 8px;margin-top: 0px;}.main{ text-align:center; width:1000px; margin-left:auto; margin-right:auto;}p{text-align:center;}</style><mce:script type="text/javascript" src="jquery.js" mce_src="jquery.js"></mce:script><mce:script type="text/javascript"><!-- var arr=new Array("634213667479687500.JPG","634195421300262500.jpg","634195421186356250.jpg","634195421108543750.jpg","634195420938543750.jpg","634195420868387500.jpg","634195420773856250.jpg","634195420689950000.jpg","634195420608856250.jpg","634195420529012500.jpg","634195420439325000.jpg","634195420352137500.jpg","634195420263856250.jpg","634195420178856250.jpg","634195420095575000.jpg","634195420006825000.jpg","634195419924168750.jpg","634195419840262500.jpg","634195419738700000.jpg","634195419624793750.jpg","634195419059637500.jpg","634195418920731250.jpg","634195418799012500.jpg","634195418653075000.jpg","634195418529637500.jpg","634195418236356250.jpg","634195418006356250.jpg","634195417855418750.jpg","634195417755106250.jpg","634195417564793750.jpg","634195417474168750.jpg","634195417386043750.jpg","634195417273856250.jpg","634195416424637500.jpg","634195416252918750.jpg","634195416151981250.jpg","634195415997918750.jpg","634195415853543750.jpg","634195414325731250.jpg","634195414195887500.jpg","634195414087762500.jpg","634195413978856250.jpg","634195413856043750.jpg","634195413744481250.jpg","634195413649012500.jpg","634195413523543750.jpg","634195413400106250.jpg","634195413300418750.jpg","634195413178387500.jpg","634195413071043750.jpg","634195412955731250.jpg","634195412816512500.jpg","634195412680731250.jpg","634195412438543750.jpg","634195412334950000.jpg","634195412168700000.jpg","634195412017137500.jpg","634195411855575000.jpg","634195411733231250.jpg","634195411629325000.jpg","634195411515106250.jpg","634195411399012500.jpg");var curPage=1,pageCount=Math.ceil(arr.length/15);function kk(lk){ $("img").attr("src",arr[ parseInt($(lk).text())-1]); $(lk).css({"background":"#fff","color":"#000"}).siblings("span.NOway").css({"background":"#b8c6aa","color":"#4c4c4c"});}function prekk(){ if(curPage>1){ $("span.NOway").each(function(index){ index++;if(index>(curPage-2)*15 && index<=(curPage-1)*15){$(this).show();}else{$(this).hide();} if(index==((curPage-2)*15+1))$(this).css({"background":"#fff","color":"#000"}).siblings("span.NOway").css({"background":"#b8c6aa","color":"#4c4c4c"}); }); curPage--;$("img").attr("src",arr[(curPage-1)*15]); } }function nextkk(){ if(curPage<pageCount){ $("span.NOway").each(function(index){ index++;if(index>(curPage*15) && index<=(curPage+1)*15){$(this).show();}else{$(this).hide();} if(index==(curPage*15+1))$(this).css({"background":"#fff","color":"#000"}).siblings("span.NOway").css({"background":"#b8c6aa","color":"#4c4c4c"}); }); curPage++;$("img").attr("src",arr[(curPage-1)*15]); } } // --></mce:script></head><body><div class="main"><p style="font-size:16px; font-weight:bold;" mce_style="font-size:16px; font-weight:bold;"></p><br /><div><img style="padding:1px; border:1px solid gray; " mce_style="padding:1px; border:1px solid gray; " alt="" src="634213667479687500.JPG" mce_src="634213667479687500.JPG" /></div><br /><br /><div><span style=" cursor:hand;" mce_style=" cursor:hand;" onclick="prekk(this)" > 上一页 </span><span class="NOway" style="cursor:hand;background-color:#fff; color:#000;" mce_style="cursor:hand;background-color:#fff; color:#000;" onclick="kk(this)"> 1 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 2 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 3 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 4 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 5 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 6 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 7 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 8 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 9 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 10 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 11 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 12 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 13 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 14 </span><span class="NOway" style="cursor:hand;" mce_style="cursor:hand;" onclick="kk(this)"> 15 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 16 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 17 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 18 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 19 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 20 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 21 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 22 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 23 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 24 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 25 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 26 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 27 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 28 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 29 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 30 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 31 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 32 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 33 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 34 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 35 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 36 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 37 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 38 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 39 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 40 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 41 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 42 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 43 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 44 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 45 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 46 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 47 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 48 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 49 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 50 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 51 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 52 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 53 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 54 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 55 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 56 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 57 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 58 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 59 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 60 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 61 </span><span class="NOway" style="display:none;cursor:hand;" mce_style="display:none;cursor:hand;" onclick="kk(this)"> 62 </span><span style=" cursor:hand;" mce_style=" cursor:hand;" onclick="nextkk(this)" > 下一页 </span></div></div><mce:script type="text/javascript"><!-- var img=document.getElementsByName("img");if(img.length>0){img=img[0];if(img.offsetWidth>1000)img.style.width="1000px";} // --></mce:script></body></html>

后台代码

protected void rp2_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "download") { int id=int.Parse(e.CommandArgument.ToString()); string valtit = (TInfo.ExecuteScalar("Title", id) as string); string html1 = "<span style="/" mce_style="/"" cursor:hand;/" onclick=/"prekk(this)/" > 上一页 </span>", html2 = "", src = "", html = "<html xmlns=/"http://www.w3.org/1999/xhtml/" ><head><meta http-equiv=/"content-type/" content=/"text/html; charset=UTF-8/" /> <meta http-equiv=/"content-language/" content=/"zh-CN/" /> <meta name=/"robots/" content=/"index,follow/" /> <meta name=/"keywords/" content=/"/" /> <meta name=/"description/" content=/"/" /> <meta name=/"rating/" content=/"general/" /> <meta name=/"author/" content=/"/" /> <meta name=/"copyright/" content=/"/" /> <meta name=/"generator/" content=/"/" /> <title>" + valtit + "</title> <mce:style type=/"text/css/"><!-- body {TEXT-ALIGN: center;margin: 0px;background-color: #b8c6aa;font-size: 12px;color: #4c4c4c;line-height: 20px;font-family: /"宋体/";height: 100%;padding:0px; margin:0px; padding-top:40px; background-image:url(images/bg.jpg); text-align:center;}img {border: 0px;}p {margin-bottom: 8px;margin-top: 0px;}.main{ text-align:center; width:1000px; margin-left:auto; margin-right:auto;}p{text-align:center;} --></mce:style><style type=/"text/css/" mce_bogus="1">body {TEXT-ALIGN: center;margin: 0px;background-color: #b8c6aa;font-size: 12px;color: #4c4c4c;line-height: 20px;font-family: /"宋体/";height: 100%;padding:0px; margin:0px; padding-top:40px; background-image:url(images/bg.jpg); text-align:center;}img {border: 0px;}p {margin-bottom: 8px;margin-top: 0px;}.main{ text-align:center; width:1000px; margin-left:auto; margin-right:auto;}p{text-align:center;}</style><mce:script type=/"text/javascript/" src="/" mce_src="/""jquery.js/"></mce:script><mce:script type=/"text/javascript/"><!-- var arr=new Array("; using (DTOperator oper = new DTOperator()) { List<TMedia> list = TMedia.GetList("ImageUrl", -1, true, "[parentid]=" + id); //DataTable table = oper.SelectPage<Media>(this.Repeater1, "[ImageUrl]", // 5000, 1, Media.OrderColumn, true, "[parentid]=" + id); if (list != null ) { Response.Clear(); Response.ContentType = "application/zip"; Response.AddHeader("content-disposition", "filename=DotNetZip.zip"); using (ZipFile zip = new ZipFile("valtit", System.Text.Encoding.Default))//解决中文乱码问题 { int index = 0; foreach (TMedia gvr in list) { string rls = Server.MapPath("/PageImages/") + gvr["ImageUrl"].ToString(); if (File.Exists(rls)) { index++; if (index == 1) src = gvr["ImageUrl"].ToString(); if(list.Count==index) html += "/"" + gvr["ImageUrl"].ToString() + "/");"; else html += "/"" + gvr["ImageUrl"].ToString() + "/","; if (index < 16) { if(index==1) html1 += "<span class=/"NOway/" style="/" mce_style="/""cursor:hand;background-color:#fff; color:#000;/" onclick=/"kk(this)/">&nbsp;" + index + "&nbsp;</span>"; else html1 += "<span class=/"NOway/" style="/" mce_style="/""cursor:hand;/" onclick=/"kk(this)/">&nbsp;" + index + "&nbsp;</span>"; } else html1 += "<span class=/"NOway/" style="/" mce_style="/""display:none;cursor:hand;/" onclick=/"kk(this)/">&nbsp;" + index + "&nbsp;</span>"; zip.AddFile(Server.MapPath("/PageImages/") + gvr["ImageUrl"].ToString(), ""); } } html1 += "<span style="/" mce_style="/"" cursor:hand;/" onclick=/"nextkk(this)/" >&nbsp;下一页&nbsp;</span>"; html += "var curPage=1,pageCount=Math.ceil(arr.length/15);function kk(lk){ $(/"img/").attr(/"src/",arr[ parseInt($(lk).text())-1]); $(lk).css({/"background/":/"#fff/",/"color/":/"#000/"}).siblings(/"span.NOway/").css({/"background/":/"#b8c6aa/",/"color/":/"#4c4c4c/"});}function prekk(){ if(curPage>1){ $(/"span.NOway/").each(function(index){ index++;if(index>(curPage-2)*15 && index<=(curPage-1)*15){$(this).show();}else{$(this).hide();} if(index==((curPage-2)*15+1))$(this).css({/"background/":/"#fff/",/"color/":/"#000/"}).siblings(/"span.NOway/").css({/"background/":/"#b8c6aa/",/"color/":/"#4c4c4c/"}); }); curPage--;$(/"img/").attr(/"src/",arr[(curPage-1)*15]); } }function nextkk(){ if(curPage<pageCount){ $(/"span.NOway/").each(function(index){ index++;if(index>(curPage*15) && index<=(curPage+1)*15){$(this).show();}else{$(this).hide();} if(index==(curPage*15+1))$(this).css({/"background/":/"#fff/",/"color/":/"#000/"}).siblings(/"span.NOway/").css({/"background/":/"#b8c6aa/",/"color/":/"#4c4c4c/"}); }); curPage++;$(/"img/").attr(/"src/",arr[(curPage-1)*15]); } } // --></mce:script></head><body><div class=/"main/"><p style="/" mce_style="/""font-size:16px; font-weight:bold;/"></p><br /><div><img style="/" mce_style="/""padding:1px; border:1px solid gray; /" alt=/"/" src="/" mce_src="/""" + src + "/" /></div><br /><br /><div>" + html1 + "</div></div><mce:script type=/"text/javascript/"><!-- var img=document.getElementsByName(/"img/");if(img.length>0){img=img[0];if(img.offsetWidth>1000)img.style.width=/"1000px/";} // --></mce:script></body></html>"; //创建HTML文件 //创建并写入(将覆盖已有文件) if (!Directory.Exists(Server.MapPath("/PageImages/dzqkhtml/")))//文件夹判断 { Directory.CreateDirectory(Server.MapPath("/PageImages/dzqkhtml/")); //创建文件夹 } else { Directory.Delete(Server.MapPath("/PageImages/dzqkhtml/"),true); Directory.CreateDirectory(Server.MapPath("/PageImages/dzqkhtml/")); } //if (!File.Exists()) //{ using (StreamWriter sw = File.CreateText(Server.MapPath("/PageImages/dzqkhtml/" + valtit + ".html"))) { sw.WriteLine(html); } //} //保存 //加入下载队列 zip.AddFile(Server.MapPath("/PageImages/dzqkhtml/" + valtit + ".html"), ""); zip.AddFile(Server.MapPath("/js/jquery.js"), ""); zip.Name = valtit; zip.Save(Response.OutputStream); } Response.End(); } } } }

 

 

 

你可能感兴趣的:(html,c,String,function,Class,border)