• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP.NET > asp.net C#实现解压缩文件的方法

asp.net C#实现解压缩文件的方法

作者: 字体:[增加 减小] 来源:互联网 时间:2017-05-11

通过本文主要向大家介绍了c#和asp.net的区别,c#asp.net教程,asp.net,asp.net教程,c# asp.net教程等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了asp.net C#实现解压缩文件的方法。一共给大家介绍了三段代码,一个是简单的解压缩单个zip文件,后一个可以解压批量的大量的但需要调用ICSharpCode.SharpZipLib.dll类了,最后一个比较实例可压缩也可以解压缩了分享给大家供大家参考。具体如下:

解压缩单个文件:

using System.IO.Compression;
string sourceFile=@"D:2.zip";
string destinationFile=@"D:1.txt";
        private const long BUFFER_SIZE = 20480;
            // make sure the source file is there
            if (File.Exists ( sourceFile ))
            {
            FileStream sourceStream = null;
            FileStream destinationStream = null;
            GZipStream decompressedStream = null;
            byte[] quartetBuffer = null;
            try
            {
                // Read in the compressed source stream
                sourceStream = new FileStream ( sourceFile, FileMode.Open );
                // Create a compression stream pointing to the destiantion stream
                decompressedStream = new DeflateStream ( sourceStream, CompressionMode.Decompress, true );
                // Read the footer to determine the length of the destiantion file
                quartetBuffer = new byte[4];
                int position = (int)sourceStream.Length - 4;
                sourceStream.Position = position;
                sourceStream.Read ( quartetBuffer, 0, 4 );
                sourceStream.Position = 0;
                int checkLength = BitConverter.ToInt32 ( quartetBuffer, 0 );
                byte[] buffer = new byte[checkLength + 100];
                int offset = 0;
                int total = 0;
                // Read the compressed data into the buffer
                while ( true )
                {
                    int bytesRead = decompressedStream.Read ( buffer, offset, 100 );
                    if ( bytesRead == 0 )
                        break;
                    offset += bytesRead;
                    total += bytesRead;
                }
                // Now write everything to the destination file
                destinationStream = new FileStream ( destinationFile, FileMode.Create );
                destinationStream.Write ( buffer, 0, total );
                // and flush everyhting to clean out the buffer
                destinationStream.Flush ( );
            }
            catch ( ApplicationException ex )
            {
                Console.WriteLine(ex.Message, "解压文件时发生错误:");
            }
            finally
            {
                // Make sure we allways close all streams
                if ( sourceStream != null )
                    sourceStream.Close ( );
                if ( decompressedStream != null )
                    decompressedStream.Close ( );
                if ( destinationStream != null )
                    destinationStream.Close ( );
            }
}</div>

批量解压缩(这需要调用一个解压缩类库。。 ICSharpCode.SharpZipLib.dll)

using System.IO;
using System.Collections.Generic;
using System.Text;
using ICSharpCode.SharpZipLib.Zip;
namespace ZipLib
{
    /// <summary>
    /// 解压缩类
    /// </summary>
   public static class ZIP
    {
  &nb

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • asp.net动态更新
  • asp.net利用母版制作页脚效果
  • Asp.net SignalR应用并实现群聊功能
  • asp.net利用反射实现给model类赋值的方法
  • Asp.net中使用DapperExtensions和反射来实现一个通用搜索
  • ASP.NET 获取客户端IP方法
  • asp.net System.Guid ToString五种格式
  • asp.net实现XML文件读取数据绑定到DropDownList的方法
  • ASP.NET Forms身份认证
  • ASP.NET动态增加HTML元素的方法实例小结

相关文章

  • 2017-05-11asp.net 组件开发中的内嵌资源引用
  • 2017-05-11MVC HtmlHelper扩展类(PagingHelper)实现分页功能
  • 2017-05-11gridview自动排序示例分享
  • 2017-05-11在ASP.NET 2.0中操作数据之六十三:GridView实现批量删除数据
  • 2017-05-11asp.net 枚举文件里面的数字绑定到DropDownList里面去
  • 2017-05-11自写一个模仿Dictionary与Foreach的实现及心得总结
  • 2017-05-11ASP.NET MVC 从IHttp到页面输出的实例代码
  • 2017-05-11使用C#处理WebBrowser控件在不同域名中的跨域问题
  • 2017-05-11asp.ne去除html的函数代码
  • 2017-05-11效控制C#中label输出文字的长度,自动换行

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • ASP.NET Mvc开发之EF延迟加载
    • gridview实现服务器端和客户端全选的两种方法分享
    • 简单好用的ASP.NET分页类(支持AJAX、自定义文字)
    • ASP.NET Ajax级联DropDownList实现代码
    • VS2015下OpenCV配置方法图文教程
    • asp.net中EXCEL数据导入到数据库的方法
    • 使用ASP.NET创建线程实例教程
    • .Net 垃圾回收机制详细介绍
    • .NET中函数Main的使用技巧
    • ASP.NET MVC3手把手教你构建Web

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有