public void SerializeToFile(T Object, string FileName, SerializeType Type, bool isZip) { FileStream msObj = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); BasicFileInformation bfi = GetBasicFileInformation(Object); string pwd = bfi.SavePassword; WriteBasicInformation(Object, msObj); Stream TargetStream; if (pwd.Length > 0) { CryptoStream cs = DesCooler.CreateEncryptStream(pwd, msObj); if (isZip) { TargetStream = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(cs); } else { TargetStream = cs; } } else { if (isZip) { TargetStream = new ICSharpCode.SharpZipLib.BZip2.BZip2OutputStream(msObj); } else { TargetStream = msObj; } } try { switch (Type) { case SerializeType.JSON: Serialize_JSON(Object, TargetStream); break; case SerializeType.Binary: Serialize_Binary(Object, TargetStream); break; } } catch {; } TargetStream.Flush(); TargetStream.Close(); msObj.Close(); }