如题.. 看遍google.. 说什么的都有. 就是没说C#怎么做的....  希望懂这方面的能指点一二..有个实例就更好了...

解决方案 »

  1.   

    压缩
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.IO;
    using System.Text;
    using System.Data;using ICSharpCode.SharpZipLib.Checksums;
    using ICSharpCode.SharpZipLib.Zip;
    using ICSharpCode.SharpZipLib.GZip;namespace AASmart.Simplify.WebServices
    {
    public static class DataUtil
    {
    private readonly static string _tableSpliter = "<tsp>";
    private readonly static string _columnSpliter = "<csp>";
    private readonly static string _rowSpliter = "<rsp>";
    private readonly static string _fieldSpilter = "<fsp>";
    private readonly static string _nullValue = "<NULL>"; public static void Serialize(DataSet dataSet, string tmpPath)
    {
    StringBuilder str = new StringBuilder();
    foreach(DataTable dataTable in dataSet.Tables)
    {
    str.Append(dataTable.TableName + _tableSpliter); foreach(DataColumn col in dataTable.Columns)
    str.Append(col.ColumnName + _columnSpliter + col.DataType.ToString() + _fieldSpilter); str.Append(_rowSpliter); foreach(DataRow dataRow in dataTable.Rows)
    {
    foreach(DataColumn col in dataTable.Columns)
    {
    if(dataRow[col.ColumnName] != DBNull.Value)
    str.Append(dataRow[col.ColumnName].ToString() + _fieldSpilter);
    else
    str.Append(_nullValue + _fieldSpilter);
    } str.Append(_rowSpliter);
    } str.Append(_tableSpliter);
    } if(!File.Exists(tmpPath))
    File.Delete(tmpPath); using(FileStream fs = File.Create(tmpPath))
    using(StreamWriter sw = new StreamWriter(fs))
    sw.Write(str.ToString());
    } public static void ZipFile(string[] files, string fileName)
    {
    Crc32 crc = new Crc32();
    ZipOutputStream outputStream = new ZipOutputStream(File.Create(fileName)); outputStream.SetLevel(6); foreach(string file in files)
    {
    FileStream fs = File.OpenRead(file); byte[] buffer = new byte[fs.Length];
    fs.Read(buffer, 0, buffer.Length);
    ZipEntry entry = new ZipEntry(Path.GetFileName(file)); entry.DateTime = DateTime.Now; entry.Size = fs.Length;
    fs.Close(); crc.Reset();
    crc.Update(buffer); entry.Crc = crc.Value; outputStream.PutNextEntry(entry); outputStream.Write(buffer, 0, buffer.Length);
    } outputStream.Finish();
    outputStream.Close();
    }
    }
    }
      

  2.   

    解压缩
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;using ICSharpCode.SharpZipLib.BZip2;
    using ICSharpCode.SharpZipLib.Zip;
    using ICSharpCode.SharpZipLib.Zip.Compression;
    using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
    using ICSharpCode.SharpZipLib.GZip;namespace AASmart.Simplify
    {
    public static class ZipLib
    {
    public static 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();
    }
    }
    }
      

  3.   

    压缩调用
    [WebMethod]
    [SoapHeader("ApplicationSoapHeader")]
    public byte[] GetTestInfo()
    {
    DataSet ds = //数据源
    try
    {
    ds.WriteXml(Server.MapPath("test.xml"));
    ds.WriteXmlSchema(Server.MapPath("test_schema.xml")); DataUtil.ZipFile(new string[] { Server.MapPath("test.xml"), Server.MapPath("test_schema.xml") }, Server.MapPath("test.zip"));
    return File.ReadAllBytes(Server.MapPath("test.zip"));
    }
    finally
    {
    File.Delete(Server.MapPath("test.xml"));
    File.Delete(Server.MapPath("test_schema.xml"));
    File.Delete(Server.MapPath("test.zip"));
    }
    }
      

  4.   

    using ICSharpCode.SharpZipLib.BZip2; 
    using ICSharpCode.SharpZipLib.Zip; 
    using ICSharpCode.SharpZipLib.Zip.Compression; 
    using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 
    using ICSharpCode.SharpZipLib.GZip; 
    string []FileProperties=new string[2]; 
    FileProperties[0]=strPath; //待解压的文件 
    FileProperties[1]=strPath+@"\";//解压后放置的目标目录 
    UnZip(FileProperties); 
    public void UnZip(string[] args) 

    ZipInputStream s = new ZipInputStream(File.OpenRead(args[0])); 
      
    ZipEntry theEntry;// = s.GetNextEntry(); 
    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(); 


    using ICSharpCode.SharpZipLib.BZip2; 
    using ICSharpCode.SharpZipLib.Zip; 
    using ICSharpCode.SharpZipLib.Zip.Compression; 
    using ICSharpCode.SharpZipLib.Zip.Compression.Streams; 
    using ICSharpCode.SharpZipLib.GZip; 
    string []FileProperties=new string[2]; 
    FileProperties[0]=strPath; //待解压的文件 
    FileProperties[1]=strPath+@"\";//解压后放置的目标目录 
    UnZip(FileProperties); 
    public void UnZip(string[] args) 

    ZipInputStream s = new ZipInputStream(File.OpenRead(args[0])); 
      
    ZipEntry theEntry;// = s.GetNextEntry(); 
    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(); 

    还可使用GZip
    还可使用GZip
      

  5.   

    解压缩//上面那个解压缩时错的 也是压缩
    public static DataSet GetData(byte[] fileBytes, string jCode)
    {
    string tempFileName = Guid.NewGuid().ToString() + ".zip";
    using (FileStream fs = File.Create(tempFileName))
    fs.Write(fileBytes, 0, fileBytes.Length);

    try
    {
    string[] properties = new string[2];
    properties[0] = tempFileName;
    properties[1] = Application.StartupPath + "/";
    ZipLib.UnZip(properties); DataSet ds = new DataSet();
    ds.ReadXmlSchema(jCode + "_schema.xml");
    ds.ReadXml(jCode + ".xml"); return ds;
    }
    finally
    {
    File.Delete(tempFileName);
    File.Delete(jCode + "_schema.xml");
    File.Delete(jCode + ".xml");
    }
    }解压缩调用DataSet ds = AppUtil.GetData(GetTestInfo(),"test")
      

  6.   

    ICSharpCode 尴尬.. 这啥东西..
    错误 3 找不到类型或命名空间名称“ICSharpCode”(是否缺少 using 指令或程序集引用?)
      

  7.   


     while ((theEntry = s.GetNextEntry()) != null) 这里报错未处理ZipException
    Wrong Local header signature: 0x21726152
      

  8.   


    public static DataSet GetData(byte[] fileBytes, string jCode)我不知道fileBytes给的什么...  ?