欢迎光临
我们一直在努力

让IE也能实现解压缩功能-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

在看dnn时发现了一个很酷的功能:能通过ie浏览器实现对zip文件的压缩和生成zip文件文件压缩包的功能。在仔细看过程序以后发现它是调用的sharpziplib.dll类库中的内容实现的压缩与解压功能。上网查了一下sharpziplib,发现它居然是开源的,在http://www.icsharpcode.net网站上有下。在网站里关于sharpziplib的源文件和调用演示包括帮助文档都有下,不过当然全是e文的。(真不知在中国有哪家公司在做.net的开源,真的十分想看国产的优秀开源项目)

在sharpziplib中实现解压的方法(演示代码):

让IE也能实现解压缩功能-.NET教程,Asp.Net开发using system;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.text;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.collections;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.io;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.diagnostics;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.runtime.serialization.formatters.binary;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.data;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.bzip2;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.zip;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.zip.compression;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.zip.compression.streams;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.gzip;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
class mainclass
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
{            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发    
// 在控制命令行下输入要解压的zip文件名
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
    public static void main(string[] args)
让IE也能实现解压缩功能-.NET教程,Asp.Net开发    
{
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
// 创建读取zip文件对象
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
        zipinputstream s = new zipinputstream(file.openread(args[0]));
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
// zip文件中的每一个文件
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
        zipentry theentry;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
// 循环读取zip文件中的每一个文件
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
        while ((theentry = s.getnextentry()) != null{
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            console.writeline(theentry.name);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
string directoryname = path.getdirectoryname(theentry.name);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
string filename      = path.getfilename(theentry.name);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
// create directory
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
            directory.createdirectory(directoryname);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
if (filename != string.empty) {
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                
// 解压文件
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
                filestream streamwriter = file.create(theentry.name);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                
int size = 2048;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                
byte[] data = new byte[2048];
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                
while (true{
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                    
// 写入数据
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
                    size = s.read(data, 0, data.length);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                    
if (size > 0{
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                        streamwriter.write(data, 
0, size);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                    }
 else {
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                        
break;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                    }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发                }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发                
让IE也能实现解压缩功能-.NET教程,Asp.Net开发                streamwriter.close();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发        }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发        s.close();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发    }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发}
让IE也能实现解压缩功能-.NET教程,Asp.Net开发

在sharpziplib中实现压缩的方法:

让IE也能实现解压缩功能-.NET教程,Asp.Net开发using system;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using system.io;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.checksums;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.zip;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
using icsharpcode.sharpziplib.gzip;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
class mainclass
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
{
让IE也能实现解压缩功能-.NET教程,Asp.Net开发    
// 输入要压缩的文件夹和要创建的zip文件文件名称
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
    public static void main(string[] args)
让IE也能实现解压缩功能-.NET教程,Asp.Net开发    
{
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
string[] filenames = directory.getfiles(args[0]);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        crc32 crc 
= new crc32();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
// 创建输出zip文件对象
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
        zipoutputstream s = new zipoutputstream(file.create(args[1]));
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
// 设置压缩等级
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
        s.setlevel(6); // 0 – store only to 9 – means best compression
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
// 循环读取要压缩的文件,写入压缩包        
让IE也能实现解压缩功能-.NET教程,Asp.Net开发
        foreach (string file in filenames) {
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            filestream fs 
= file.openread(file);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
byte[] buffer = new byte[fs.length];
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            fs.read(buffer, 
0, buffer.length);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            zipentry entry 
= new zipentry(file);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            entry.datetime 
= datetime.now;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            entry.size 
= fs.length;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            fs.close();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            crc.reset();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            crc.update(buffer);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            entry.crc  
= crc.value;
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            s.putnextentry(entry);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            s.write(buffer, 
0, buffer.length);
让IE也能实现解压缩功能-.NET教程,Asp.Net开发            
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发        
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        s.finish();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发        s.close();
让IE也能实现解压缩功能-.NET教程,Asp.Net开发    }

让IE也能实现解压缩功能-.NET教程,Asp.Net开发}

  类中应该还有其他功能,还没有来得及看。具体sharpziplib中是如何实行的也还没有来得及看,先试一试最简单功能,大家有兴趣可以下载看看。默认提供的演示程序是控制台下运行的(好像还有其他环境中运行的,不过我没有试),我照着做了一个web应用程序的,希望能对大家有用。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 让IE也能实现解压缩功能-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章