解决方案 »

  1.   


    //转贴
    public static string CompressString(string unCompressedString)
    {
       byte[] bytData = System.Text.Encoding.UTF8.GetBytes(unCompressedString);
       MemoryStream ms = new MemoryStream();
       Stream s = null;
       try
       {
         s = new GZipStream(ms, CompressionMode.Compress);
         int totalRead = 0;
         int bufLen = 4096;
         int thisRead = 0;
         while (true)
         {
           if (totalRead < bytData.Length)
           {
             thisRead = bytData.Length - totalRead;
             if (thisRead > bufLen)
               thisRead = bufLen;
             s.Write(bytData, totalRead, thisRead);
             totalRead = totalRead + thisRead;
           }
           else
             break;
        }                
      }
      catch (Exception e)
      {
        LogUtil.LogError("Compress String Error:" + e.Message);
      }
      finally
      {
        if (s != null)
        {                    
           s.Close();
           s.Dispose();
           s = null;
        }
      }
      byte[] compressedData = (byte[])ms.ToArray();
      ms.Close();
      ms.Dispose();
      return System.Convert.ToBase64String(compressedData, 0, compressedData.Length);
    }
      

  2.   

    这个很详细http://dobon.net/vb/dotnet/links/createzipfile.html
      

  3.   

    GZipStream只对文本中重复的字符压缩,二进制不压缩,没啥大的作用