using Telerik.Windows.Zip; /// <summary> /// 利用telerik的zip库压缩字符串 /// </summary> /// <param name="str"></param> /// <returns></returns> public static string CompressString(string str) { string result = string.Empty; try { var memoryStream = new MemoryStream(); var zipOutputStream = new ZipOutputStream(memoryStream, ZipCompression.Default); var writer = new StreamWriter(zipOutputStream); writer.Write(str); writer.Flush(); result = Convert.ToBase64String(memoryStream.ToArray()); } catch { } return result; } /// <summary> /// 利用telerik的zip库解压字符串 /// </summary> /// <param name="compressedBase64String"></param> /// <returns></returns> public static string UnCompressString(string compressedBase64String) { string result = string.Empty; try { var memoryStream = new MemoryStream(Convert.FromBase64String(compressedBase64String)); var input = new ZipInputStream(memoryStream); var reader = new StreamReader(input); result = reader.ReadToEnd(); } catch { } return result; }