public void SaveSearch(string filepath, List <UInt32> resultsList, Dump searchDump) { ZipOutputStream outstream = new ZipOutputStream(filepath); outstream.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed; BinaryFormatter formatter = new BinaryFormatter(); // First entry is the dump outstream.PutNextEntry("dump"); //DateTime start = Logger.WriteLineTimedStarted("compressing search dump"); // Must put the addresses first, so that it can derive the right number of bytes to read for the dump formatter.Serialize(outstream, searchDump.StartAddress); formatter.Serialize(outstream, searchDump.EndAddress); outstream.Write(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress)); //Logger.WriteLineTimedFinished("compressing search dump", start); // Second entry is the list outstream.PutNextEntry("list"); //start = Logger.WriteLineTimedStarted("compressing search list"); formatter.Serialize(outstream, resultsList); //Logger.WriteLineTimedFinished("compressing search list", start); outstream.Close(); outstream.Dispose(); }
//public static void ZipFile(string path, string file2Zip, string zipFileName, string zip, string bldgType) public static void ZipFile(string path, string file2Zip, string zipFileName) { //MemoryStream ms = InitializeGbxml(path + file2Zip, zip, bldgType) as MemoryStream; MemoryStream ms = InitializeGbxml(Path.Combine(path, file2Zip)) as MemoryStream; string compressedFile = Path.Combine(path, zipFileName); if (File.Exists(compressedFile)) { File.Delete(compressedFile); } Crc32 objCrc32 = new Crc32(); ZipOutputStream strmZipOutputStream = new ZipOutputStream(File.Create(compressedFile)); strmZipOutputStream.SetLevel(9); byte[] gbXmlBuffer = new byte[ms.Length]; ms.Read(gbXmlBuffer, 0, gbXmlBuffer.Length); ZipEntry objZipEntry = new ZipEntry(file2Zip); objZipEntry.DateTime = DateTime.Now; objZipEntry.Size = ms.Length; ms.Close(); objCrc32.Reset(); objCrc32.Update(gbXmlBuffer); objZipEntry.Crc = objCrc32.Value; strmZipOutputStream.PutNextEntry(objZipEntry); strmZipOutputStream.Write(gbXmlBuffer, 0, gbXmlBuffer.Length); strmZipOutputStream.Finish(); strmZipOutputStream.Close(); strmZipOutputStream.Dispose(); }
public void Dispose() { if (_Stream != null) { _Stream.Dispose(); } }
/// <summary> /// 压缩 /// </summary> /// <param name="sourceFolder">压缩目录</param> /// <param name="DestFile">压缩成文件</param> /// <returns>成功与否</returns> private bool StartZip(string sourceFolder, string DestFile) { try { string[] filenames = Directory.GetFiles(sourceFolder); ZipOutputStream s = new ZipOutputStream(System.IO.File.Create(DestFile)); s.SetLevel(5); FileStream fs; foreach (string file in filenames) { fs = System.IO.File.OpenRead(file); byte[] buffer = new byte[fs.Length]; fs.Read(buffer, 0, buffer.Length); ZipEntry entry = new ZipEntry(file.Replace(sourceFolder, "")); s.PutNextEntry(entry); s.Write(buffer, 0, buffer.Length); fs.Close(); } s.Finish(); s.Close(); s.Dispose(); return(true); } catch (Exception e) { MyCommon.ShowInfo("文件生成失败:" + e.Message); return(false); } }
public void WriteCompressedZip(string filepath) { ZipOutputStream outstream = new ZipOutputStream(filepath); outstream.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed; BinaryFormatter formatter = new BinaryFormatter(); outstream.PutNextEntry("dump"); DateTime startTime = DateTime.Now; formatter.Serialize(outstream, searchDump.StartAddress); formatter.Serialize(outstream, searchDump.EndAddress); outstream.Write(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress)); DateTime endTime = DateTime.Now; outstream.PutNextEntry("list"); startTime = DateTime.Now; List <uint> copy = new List <uint>(resultsList); endTime = DateTime.Now; startTime = DateTime.Now; formatter.Serialize(outstream, resultsList); endTime = DateTime.Now; outstream.Close(); outstream.Dispose(); }
public static void CreateZIP(Dictionary<string, string> inputTargetPaths, string zipPath, string password) { using (FileStream fsOut = File.Create(zipPath)) using (var zipStream = new ZipOutputStream(fsOut)) { //Code got from https://github.com/icsharpcode/SharpZipLib/wiki/Create-a-Zip-with-full-control-over-content //0-9, 9 being the highest level of compression zipStream.SetLevel(3); zipStream.Password = password; foreach (var inputPath in inputTargetPaths.Keys) { var fi = new FileInfo(inputPath); var newEntry = new ZipEntry(inputTargetPaths[inputPath]); newEntry.DateTime = fi.LastWriteTime; newEntry.Size = fi.Length; zipStream.PutNextEntry(newEntry); // Zip the file in buffered chunks var buffer = new byte[4096]; using (FileStream fsInput = File.OpenRead(inputPath)) { StreamUtils.Copy(fsInput, zipStream, buffer); } zipStream.Flush(); zipStream.CloseEntry(); } zipStream.Dispose(); } }
protected override void Dispose(bool disposing) { if (disposing) { archive.Dispose(); } }
override public void Post() { base.Post(); _zip.Close(); _zip.Dispose(); }
public void Dispose() { if (z != null) { z.Dispose(); z = null; } }
/* * Actual implementation of Dispose method */ void Dispose(bool disposing) { if (!_disposed && disposing) { _disposed = true; _zipStream.Dispose(); } }
public void Dispose() { if (_zipOutputStream != null) { _zipOutputStream.Dispose(); _zipOutputStream = null; } }
public string ZipFiles(string path, string password, string comment) { logger.Debug("zip file in : " + path); string zipPath = ""; ZipOutputStream zos = null; try { zipPath = path + @"\" + Path.GetFileName(path) + comment + ".zip"; ArrayList files = GetFiles(path); zos = new ZipOutputStream(File.Create(zipPath)); if (password != null && password != string.Empty) { zos.Password = password; } if (comment != null && comment != "") { zos.SetComment(comment); } zos.SetLevel(9);//Compression level 0-9 (9 is highest) byte[] buffer = new byte[4096]; foreach (string f in files) { ZipEntry entry = new ZipEntry(Path.GetFileName(f)); entry.DateTime = DateTime.Now; zos.PutNextEntry(entry); FileStream fs = File.OpenRead(f); int sourceBytes; do { sourceBytes = fs.Read(buffer, 0, buffer.Length); zos.Write(buffer, 0, sourceBytes); } while (sourceBytes > 0); fs.Close(); fs.Dispose(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (zos != null) { zos.Finish(); zos.Close(); zos.Dispose(); } } return(zipPath); }
public static String CompressionFichier(String pFichier, int pCapaciteReception) { try { //GC.Collect(); if (File.Exists(pFichier)) { var infofile = new FileInfo(pFichier); var directoryPath = infofile.DirectoryName; string sNomFichier = infofile.Name; var sCapacite = infofile.Length; var sExt = infofile.Extension; var sNomFichierZip = sNomFichier.Replace(sExt, ""); sCapacite = sCapacite / 1024; if (Convert.ToInt32(sCapacite) >= pCapaciteReception) { //pFichier= Compress(infofile); using (var s = new ZipOutputStream(File.Create(String.Format("{0}\\{1}.zip", directoryPath, sNomFichierZip)))) { s.SetLevel(9); var buffer = new byte[4096]; var entry = new ZipEntry(sNomFichierZip + sExt) { DateTime = DateTime.Now }; s.PutNextEntry(entry); using (FileStream fs = File.OpenRead(pFichier)) { int sourceBytes; do { sourceBytes = fs.Read(buffer, 0, buffer.Length); s.Write(buffer, 0, sourceBytes); }while (sourceBytes > 0); fs.Close(); fs.Dispose(); } s.Finish(); s.Close(); s.Dispose(); pFichier = infofile.DirectoryName + "\\" + string.Format("{0}.zip", sNomFichierZip); } } } return(pFichier); } catch (Exception ex) { throw ex; } finally { //GC.Collect(); } }
public void Dispose() { if (_zos != null) { _zos.Finish(); _zos.Dispose(); _zos = null; } }
/// <summary> /// Zips the package. /// </summary> /// <param name="Path">The path.</param> /// <param name="savePath">The save path.</param> public static void ZipPackage(string Path, string savePath) { string OutPath = savePath; ArrayList ar = GenerateFileList(Path); // generate file list // find number of chars to remove from orginal file path int TrimLength = (Directory.GetParent(Path)).ToString().Length; TrimLength += 1; //remove '\' FileStream ostream; byte[] obuffer; ZipOutputStream oZipStream = new ZipOutputStream(System.IO.File.Create(OutPath)); // create zip stream oZipStream.SetLevel(9); // 9 = maximum compression level ZipEntry oZipEntry; foreach (string Fil in ar) // for each file, generate a zipentry { oZipEntry = new ZipEntry(Fil.Remove(0, TrimLength)); oZipStream.PutNextEntry(oZipEntry); if (!Fil.EndsWith(@"/")) // if a file ends with '/' its a directory { ostream = File.OpenRead(Fil); obuffer = new byte[ostream.Length]; // byte buffer ostream.Read(obuffer, 0, obuffer.Length); oZipStream.Write(obuffer, 0, obuffer.Length); ostream.Close(); } } oZipStream.Finish(); oZipStream.Close(); oZipStream.Dispose(); oZipStream = null; oZipEntry = null; ostream = null; ar.Clear(); ar = null; }
protected override void Dispose(bool disposing) { if (!disposing) { return; } _zipStream.Close(); _zipStream.Dispose(); }
/// <summary> /// Writes a zip file. /// </summary> /// <param name="filesToZip">The files to zip.</param> /// <param name="path">The destination path.</param> /// <param name="compression">The compression level.</param> public static void ToFile(string sourceFile, string zipFileName) { //reading buffer byte[] mBuffer = new Byte[200000]; //bytes read out int bytesRead; //create new zip archive ZipOutputStream zipStream = new ZipOutputStream(File.Create(zipFileName)); zipStream.SetLevel(9); //create new checksum Crc32 crc32 = new Crc32(); //create new zip entry FileInfo fi = new FileInfo(sourceFile); ZipEntry entry = new ZipEntry(Path.GetFileName(sourceFile)); entry.DateTime = fi.LastWriteTime; entry.Size = fi.Length; //open source file FileStream sourceFileStream = File.OpenRead(sourceFile); //reset CRC crc32.Reset(); //add new entry to zip file zipStream.PutNextEntry(entry); //read source file while (sourceFileStream.Position < sourceFileStream.Length) { bytesRead = sourceFileStream.Read(mBuffer, 0, mBuffer.Length); zipStream.Write(mBuffer, 0, bytesRead); crc32.Update(mBuffer, 0, bytesRead); } //store CRC value of this entry entry.Crc = crc32.Value; //close entry zipStream.CloseEntry(); //close source file sourceFileStream.Close(); //close zip archive zipStream.Finish(); zipStream.Flush(); zipStream.Close(); zipStream.Dispose(); }
public void Dispose() { if (zipOutput != null) { zipOutput.Dispose(); } if (zipFile != null) { zipFile.Close(); } }
/// <summary> /// Creates a ZIP archive using the specified dictionary. /// The keys in the dictionary are the paths of the files as they should appear in the archive. /// The values in the dictionary are the absolute paths to the files on the local filesystem. /// </summary> /// <exception cref="UnauthorizedAccessException">The caller does not have the required permission.-or- <paramref name="archiveFilePath" /> specified a file that is read-only. </exception> /// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. </exception> /// <exception cref="DirectoryNotFoundException">The specified path is invalid (for example, it is on an unmapped drive). </exception> /// <exception cref="IOException">An I/O error occurred while creating the file. </exception> /// <exception cref="NotSupportedException"><paramref name="archiveFilePath" /> is in an invalid format. </exception> /// <exception cref="SecurityException">The caller does not have the required permission. </exception> /// <exception cref="FileNotFoundException">One of the elements within <paramref name="zipContents" /> points to a file that does not exist. </exception> public static void CreateZip(String archiveFilePath, Dictionary <String, String> zipContents) { using (FileStream fsOut = File.Create(archiveFilePath)) { var zipStream = new ZipOutputStream(fsOut); zipStream.SetLevel(9); // Compression Level: Valid range is 0-9, with 9 being the highest level of compression. foreach (var content in zipContents) { String archivePath = content.Key; // The location of the file as it appears in the archive. String filePath = content.Value; // The location of the file as it exists on disk. // Skip files that have no path. if (String.IsNullOrWhiteSpace(filePath)) { continue; } // Skip files that do not exist. if (!File.Exists(filePath)) { continue; } FileInfo fi = new FileInfo(filePath); // Makes the name in zip based on the folder String entryName = archivePath; // Removes drive from name and fixes slash direction entryName = ZipEntry.CleanName(entryName); var newEntry = new ZipEntry(entryName); newEntry.DateTime = fi.LastWriteTime; // Note: Zip format stores 2 second granularity newEntry.Size = fi.Length; zipStream.PutNextEntry(newEntry); // Zip the file in buffered chunks // the "using" will close the stream even if an exception occurs var buffer = new byte[4096]; using (FileStream streamReader = File.OpenRead(filePath)) { StreamUtils.Copy(streamReader, zipStream, buffer); } zipStream.CloseEntry(); } zipStream.IsStreamOwner = true; // Makes the Close also Close the underlying stream zipStream.Close(); zipStream.Dispose(); } }
} // proc CreateZipStream private void CloseZipStream(FileWrite zipStream, ZipOutputStream zip) { if (zip != null) { zip.Flush(); zip.Dispose(); } if (zipStream != null) { zipStream.Dispose(); } } // proc CloseZipStream
/// <summary> /// 制作压缩包(多个文件压缩到一个压缩包,支持加密、注释) /// </summary> /// <param name="lstFileBytes">文件流列表</param> /// <param name="zipFileName">压缩包文件名</param> /// <param name="compresssionLevel">压缩级别 1-9</param> /// <param name="password">密码</param> /// <param name="comment">注释</param> /// <returns></returns> public ZipFilesOut ZipFiles(List <FileBytes> lstFileBytes, string zipFileName, int compresssionLevel, string password, string comment) { ZipFilesOut zipFilesResult = new ZipFilesOut(); MemoryStream memoryStream = new MemoryStream(); #region 创建压缩文件 try { using (ZipOutputStream zos = new ZipOutputStream(memoryStream)) { if (compresssionLevel != 0) { zos.SetLevel(compresssionLevel);//设置压缩级别 } if (!string.IsNullOrEmpty(password)) { zos.Password = password;//设置zip包加密密码 } if (!string.IsNullOrEmpty(comment)) { zos.SetComment(comment);//设置zip包的注释 } foreach (var item in lstFileBytes) { ZipEntry entry = new ZipEntry(item.FileName); entry.IsUnicodeText = true;//避免中文乱码 zos.PutNextEntry(entry); zos.Write(item.FileByte, 0, item.FileByte.Length); } zos.Dispose(); zipFilesResult.FileByte = memoryStream.ToArray(); zipFilesResult.IsSuccess = true; zipFilesResult.Message = "生成压缩文件成功!"; } } catch { memoryStream.Dispose(); memoryStream.Close(); zipFilesResult.IsSuccess = false; zipFilesResult.Message = "生成压缩文件失败!"; } #endregion return(zipFilesResult); }
private void bkg_Archive(object filenamePair) { KeyValuePair <string, string> pair = (KeyValuePair <string, string>)filenamePair; string fileName = pair.Key; string newFileName = pair.Value; string zipfileName = Path.ChangeExtension(fileName, "zip"); string zipEntryName = Path.GetFileName(newFileName); lock (archiveSyncLock) { zipEntryName = GetNewZipEntryFileName(fileName, zipEntryName, 1, zipfileName, null); Dictionary <string, string> zipItems = new Dictionary <string, string>(); if (File.Exists(zipfileName)) { ZipFile zip = new ZipFile(zipfileName); IEnumerable <ZipEntry> zes = zip.Cast <ZipEntry>(); foreach (ZipEntry zie in zes) { zipItems.Add( zie.Name, new StreamReader( zip.GetInputStream(zie)).ReadToEnd()); } zip.Close(); } FileStream fs = File.Open(zipfileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite); ZipOutputStream zos = new ZipOutputStream(fs); //Считываем все из старого файла byte[] content = File.ReadAllBytes(newFileName); //Создаем файлы в архиве foreach (var item in zipItems) { ZipEntry ze = new ZipEntry(item.Key); zos.PutNextEntry(ze); byte[] itemContent = Encoding.Default.GetBytes(item.Value); zos.Write(itemContent, 0, itemContent.Length); } ZipEntry zipe = new ZipEntry(zipEntryName); zos.PutNextEntry(zipe); zos.Write(content, 0, content.Length); zos.Flush(); zos.Close(); zos.Dispose(); fs.Close(); fs.Dispose(); if (File.Exists(newFileName)) { File.Delete(newFileName); } } }
public void ZipFile(string strFile, string strZip) { if (strFile[strFile.Length - 1] != Path.DirectorySeparatorChar) { strFile += Path.DirectorySeparatorChar; } ZipOutputStream s = new ZipOutputStream(File.Create(strZip)); s.SetLevel(6); // 0 - store only to 9 - means best compression zip(strFile, s, strFile); s.Finish(); s.Dispose(); s.Close(); }
public byte[] GetOutput() { CheckInvalid(); _zipOutStream.Finish(); _zipOutStream.Close(); _zipOutStream.Dispose(); BinaryReader reader = new BinaryReader(File.Open(_outPath, FileMode.Open)); byte[] arr = new byte[reader.BaseStream.Length]; reader.Read(arr, 0, arr.Length); reader.Close(); File.Delete(_outPath); _invalid = true; return(arr); }
protected override void Dispose(bool disposing) { if (!disposed) { if (disposing) { if (zip != null) { zip.Flush(); zip.Dispose(); } disposed = true; } } base.Dispose(disposing); }
public void CreateZipFiles(string inputFolderPath, string outputPath, bool pickRecursive = false, string fileSearchPattern = "", string password = "") { var fileList = GenerateFileList(inputFolderPath, fileSearchPattern, pickRecursive); // generate file list int trimLength = (Directory.GetParent(inputFolderPath)).ToString().Length; // find number of chars to remove // from orginal file path trimLength += 1; //remove '\' byte[] obuffer; FileStream fsOut = File.Create(outputPath); var oZipStream = new ZipOutputStream(fsOut); // create zip stream if (!string.IsNullOrEmpty(password)) { oZipStream.Password = password; } oZipStream.SetLevel(9); // maximum compression ZipEntry oZipEntry; foreach (string fil in fileList) // for each file, generate a zipentry { oZipEntry = new ZipEntry(fil.Remove(0, trimLength)); oZipStream.PutNextEntry(oZipEntry); if (!fil.EndsWith(@"/")) // if a file ends with '/' its a directory { var ostream = File.OpenRead(fil); obuffer = new byte[ostream.Length]; ostream.Read(obuffer, 0, obuffer.Length); oZipStream.Write(obuffer, 0, obuffer.Length); ostream.Close(); ostream.Dispose(); } } oZipStream.Finish(); oZipStream.Close(); oZipStream.Dispose(); fsOut.Close(); fsOut.Dispose(); }
public static byte[] Pack() { var ms = new MemoryStream(); //We write in front of the header so that the zip can't be read //or flagged by AV software ms.WriteByte(7); ms.WriteByte(0); ms.WriteByte(7); var zipFile = new ZipOutputStream(ms); zipFile.IsStreamOwner = false; zipFile.SetLevel(9); var header = new ModHeader(); header.Name = Program.name; header.Major = DependencyResolver.ParseVersionMajor(Program.version); header.Minor = DependencyResolver.ParseVersionMinor(Program.version); header.Tag = DependencyResolver.ParseVersionTag(Program.version); header.CodeFiles = Archive(zipFile, Program.srcFiles); header.ImageFiles = ArchiveImages(zipFile, Program.imageAssets); header.ComponentFiles = ArchiveComponents(zipFile, Program.components); header.DLLFiles = Archive(zipFile, Program.dlls); header.SoundFiles = ArchiveAudio(zipFile, Program.soundAssets); header.MapFiles = Archive(zipFile, Program.maps); header.DatabaseUrl = DependencyResolver.GetModUrl(Program.name); header.Description = Program.description; header.Dependencies = BuildDependencies(); var headerString = JsonConvert.SerializeObject(header, Formatting.Indented); WriteFile(zipFile, "mod.json", headerString); zipFile.Close(); zipFile.Dispose(); ms.Seek(0, SeekOrigin.Begin); var data = ms.ToArray(); ms.Dispose(); return(ms.ToArray()); }
public void WriteCompressedZip(string filepath) { ZipOutputStream outstream = new ZipOutputStream(filepath); outstream.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed; BinaryFormatter formatter = new BinaryFormatter(); outstream.PutNextEntry("dump"); //Logger.WriteLineTimed("Started compressing search dump"); DateTime startTime = DateTime.Now; formatter.Serialize(outstream, searchDump.StartAddress); formatter.Serialize(outstream, searchDump.EndAddress); outstream.Write(searchDump.mem, 0, (int)(searchDump.EndAddress - searchDump.StartAddress)); DateTime endTime = DateTime.Now; //Logger.WriteLineTimed("Finished compressing search dump in " + (new TimeSpan(endTime.Ticks - startTime.Ticks).TotalSeconds)); outstream.PutNextEntry("list"); //Logger.WriteLineTimed("Started copying search list"); startTime = DateTime.Now; List <UInt32> copy = new List <uint>(resultsList); endTime = DateTime.Now; //Logger.WriteLineTimed("Finished copying search list in " + (new TimeSpan(endTime.Ticks - startTime.Ticks).TotalSeconds)); //Logger.WriteLineTimed("Started compressing search list"); startTime = DateTime.Now; formatter.Serialize(outstream, resultsList); endTime = DateTime.Now; //Logger.WriteLineTimed("Finished compressing search list in " + (new TimeSpan(endTime.Ticks - startTime.Ticks).TotalSeconds)); outstream.Close(); outstream.Dispose(); }
public byte[] SerializeWithImage() { var ms = new MemoryStream(); var oStr = new ZipOutputStream(ms); WriteFile(oStr, "info.json", Encoding.UTF8.GetBytes(Serialize().Serialize())); WriteFile(oStr, "image.png", SaveImg()); oStr.Flush(); oStr.Close(); oStr.Dispose(); var arr = ms.ToArray(); ms.Close(); ms.Dispose(); return(arr); }
/// <summary> /// 压缩多层目录 /// </summary> /// <param name="strDirectory">The directory.</param> /// <param name="zipedFile">The ziped file.</param> /// example: D:/creator/7ad236356ebd036f6c4e31178b5384b575cbeff8_201903061614291429/ public bool ZipFileDirectory(string strDirectory, string zipedFile, bool includeDir, ref float progress) { totalLen = getAllFileLength(strDirectory); Debug.Log("总长度------>" + totalLen); string fdir = strDirectory.Replace("\\", "/"); fdir = fdir.Substring(0, fdir.Length - 1); Debug.Log("fdir------>" + fdir); if (includeDir) { rootDir = fdir.Substring(fdir.LastIndexOf("/") + 1); rootDir += "/"; } else { rootDir = ""; } using (System.IO.FileStream ZipFile = System.IO.File.Create(zipedFile)) { using (ZipOutputStream s = new ZipOutputStream(ZipFile)) { try { s.UseZip64 = UseZip64.Off; s.SetLevel(8); ZipSetp(strDirectory, s, rootDir, includeDir, ref progress, Path.GetFileName(zipedFile)); progress = 1; } catch (System.Exception e) { Debug.Log("压缩出错了" + e.ToString()); progress = 0; } finally { s.Finish(); s.Close(); s.Dispose(); } } } return(progress >= 1 ? true : false); }
internal void Save(Stream stream) { var enc = Encoding.UTF8; ZipOutputStream os = new ZipOutputStream(stream, true); os.CompressionLevel = (OfficeOpenXml.Packaging.Ionic.Zlib.CompressionLevel)_compression; /**** ContentType****/ var entry = os.PutNextEntry("[Content_Types].xml"); byte[] b = enc.GetBytes(GetContentTypeXml()); os.Write(b, 0, b.Length); /**** Top Rels ****/ _rels.WriteZip(os, "_rels\\.rels"); ZipPackagePart ssPart=null; foreach(var part in Parts.Values) { if (part.ContentType != ExcelPackage.contentTypeSharedString) { part.WriteZip(os); } else { ssPart = part; } } //Shared strings must be saved after all worksheets. The ss dictionary is populated when that workheets are saved (to get the best performance). if (ssPart != null) { ssPart.WriteZip(os); } os.Flush(); os.Close(); os.Dispose(); //return ms; }