通过使用第三方DLL,我已经编写了代码压缩文件夹到zip但没有使用任何第三方DLL是否可能。 [英] by using third party dll i have wrote teh code to compress a folder to zip but with out using any third party dll is it possible.
本文介绍了通过使用第三方DLL,我已经编写了代码压缩文件夹到zip但没有使用任何第三方DLL是否可能。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我...
使用第三方dll代码是:
please help me...
by using third party dll the code is :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zip;
namespace compression
{
class Program
{
static void Main(string[] args)
{
using (var zip = new Ionic.Zip.ZipFile())
{
zip.AddDirectory("Stuff", "rootInZipFile");
zip.Save("Stuff.zip");
}
}
}
}
推荐答案
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string sFileToZip = @"D:\code.txt";
string sZipFile = @"D:\code.zip";
using (FileStream __fStream = File.Open(sZipFile, FileMode.Create))
{
GZipStream obj = new GZipStream(__fStream, CompressionMode.Compress);
byte[] bt = File.ReadAllBytes(sFileToZip);
obj.Write(bt, 0, bt.Length);
obj.Close();
obj.Dispose();
}
}
}
}
是的可能。
解决方案:
http://msdn.microsoft.com/en-us/library/dd267698.aspx [ ^ ](框架> = 4.0)
http://weblogs.asp.net/jgalloway/archive/2007/10/25/creating-zip-archives-in-net-without-an-external-library-like-sharpziplib.aspx [ ^ ]
Hi,
Yes its possible.
Solution :
http://msdn.microsoft.com/en-us/library/dd267698.aspx[^] (Framework >= 4.0)
http://weblogs.asp.net/jgalloway/archive/2007/10/25/creating-zip-archives-in-net-without-an-external-library-like-sharpziplib.aspx[^]
是,您可以压缩文件夹和文件而不用一个第三方工具。
.NET在 System.IO.Compression 命名空间中提供压缩类。
试一试。祝你好运......
YES, you can compress folder(s) and file(s) without any third party tool.
.NET provides classes for compression in System.IO.Compression namespace.
Try it. best of luck...
这篇关于通过使用第三方DLL,我已经编写了代码压缩文件夹到zip但没有使用任何第三方DLL是否可能。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文