当前位置: 首页 > news >正文

h5素材做多的网站上海手机网站案例

h5素材做多的网站,上海手机网站案例,南京哪家网站建设好,wordpress 两个菜单真是折腾呀,网上虽然有不少的源码但测试几个就是不成功,经过折腾还是折腾出来了现在分享出来给大家。 源码还是在网友们的基础上调整的,主要是调整源码大大小写格式。 sharpziplib.dll 下载:http://pan.baidu.com/share/link?sh…

真是折腾呀,网上虽然有不少的源码但测试几个就是不成功,经过折腾还是折腾出来了现在分享出来给大家。

源码还是在网友们的基础上调整的,主要是调整源码大大小写格式。


sharpziplib.dll 下载:http://pan.baidu.com/share/link?shareid=1016448925&uk=134565274&fid=3214033513

首先需要在项目里引用sharpziplib.dll

ZipClass.cs 类函数 包括压缩和解压

using System;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.Checksums;
namespace Updatezip
{#region 压缩文件类/// <summary>/// 压缩文件   /// </summary>public class ZipClass{public void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize){//如果文件没有找到,则报错   if (!System.IO.File.Exists(FileToZip)){throw new System.IO.FileNotFoundException("The specified file " + FileToZip + " could not be found. Zipping aborderd");}System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);ZipEntry ZipEntry = new ZipEntry("ZippedFile");ZipStream.PutNextEntry(ZipEntry);ZipStream.SetLevel(CompressionLevel);byte[] buffer = new byte[BlockSize];System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);ZipStream.Write(buffer, 0, size);try{while (size < StreamToZip.Length){int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);ZipStream.Write(buffer, 0, sizeRead);size += sizeRead;}}catch (System.Exception ex){throw ex;}ZipStream.Finish();ZipStream.Close();StreamToZip.Close();}public void ZipFileMain(string[] args){string[] filenames = Directory.GetFiles(args[0]);Crc32 Crc = new Crc32();ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));s.SetLevel(6); // 0 - store only to 9 - means best compression   foreach (string file in filenames){//打开压缩文件   FileStream fs = File.OpenRead(file);byte[] buffer = new byte[fs.Length];fs.Read(buffer, 0, buffer.Length);ZipEntry entry = new ZipEntry(file);entry.DateTime = DateTime.Now;// set Size and the crc, because the information   // about the size and crc should be stored in the header   // if it is not set it is automatically written in the footer.   // (in this case size == crc == -1 in the header)   // Some ZIP programs have problems with zip files that don"t store   // the size and crc in the header.   entry.Size = fs.Length;fs.Close();Crc.Reset();Crc.Update(buffer);entry.Crc = Crc.Value;s.PutNextEntry(entry);s.Write(buffer, 0, buffer.Length);}s.Finish();s.Close();}}
#endregion#region 解压文件类/// <summary>///  解压文件/// </summary>public class UnZipClass{public void UnZip(string[] args){ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));ZipEntry theEntry;while ((theEntry = s.GetNextEntry()) != null){string directoryName = Path.GetDirectoryName(args[1]);string fileName = Path.GetFileName(theEntry.Name);//生成解压目录   Directory.CreateDirectory(directoryName);if (fileName != String.Empty){//解压文件到指定的目录   FileStream streamWriter = File.Create(args[1] + theEntry.Name);int size = 2048;byte[] data = new byte[2048];while (true){size = s.Read(data, 0, data.Length);if (size > 0){streamWriter.Write(data, 0, size);}else{break;}}streamWriter.Close();}}s.Close();}}
#endregion
}

调用方法

/// <summary>   
/// 调用源码   
/// </summary>   
private void button2_Click_1(object sender, System.EventArgs e)  
{  string[] FileProperties = new string[2];  FileProperties[0] = "C:\\unzipped\\";//待压缩文件目录   FileProperties[1] = "C:\\zip\\a.zip"; //压缩后的目标文件   ZipClass Zc = new ZipClass();  Zc.ZipFileMain(FileProperties);  
}  
private void button2_Click(object sender, System.EventArgs e)  
{  string[] FileProperties = new string[2];  FileProperties[0] = "C:\\zip\\test.zip";//待解压的文件   FileProperties[1] = "C:\\unzipped\\";//解压后放置的目标目录   UnZipClass UnZc = new UnZipClass();  UnZc.UnZip(FileProperties);  
}


http://www.yayakq.cn/news/96849/

相关文章:

  • 抽奖网站建设泉州建设培训中心网站
  • 做海外贸易网站关于大棚建设的网站
  • 做阿里巴巴网站wordpress设置网址错
  • 太平洋建设官方网站wordpress地图在哪
  • 某企业网站建设方案2000字点墨网站
  • 服务好的网站建设公司制作公司网页要多长时间
  • cc域名有哪些知名网站北京网站设计公司新
  • 学校网站怎么做推广百度网站ip地址
  • 影视app源码seo技术导航
  • 建设一个网站要学什么个人建设视频网站
  • 网站seo技术如何去掉链接wordpress
  • 济源网站制作计算机网站设计
  • 微信公众号开发微网站开发群晖服务器做网站
  • 企业建设网站怎么做账网站优化排名哪家好
  • 贷款平台代理怎么加入app优化排名
  • jquery网站后台如何增加网站点击量
  • 申请建设工作网站的函如何做国外网站
  • 网页制作模板的淘宝网站代码世界500强企业logo图片
  • 海淀周边网站建设制作一个收费网站要多少钱
  • 济宁做网站的WordPress播放背景音乐
  • seo整站优化吧做问答的网站
  • 专业定制网站建设代理桂林新闻
  • 网站备案在哪里审批做php网站方向要会什么
  • 建设部资质查询网站网站建设方案哪家好 推荐
  • 医院门户网站建设建个大型网站需
  • 室内设计网站知乎单一产品企业或多元化产品企业的网站建设与策划有什么不同?
  • 关于网站建设的申请asp.net网站建设教程
  • 建设银行网站怎么不可登入郑州最好的男科医院是什么医院
  • 东莞寮步做网站的有吗小程序一键开发免费
  • 百度网站的网址万户网站做的怎样