Hello
In my .NET application I have the following problem. I'm trying to update file in Zip and doing this:
public void Save(ZipDirectory dir, string fileName) { using (var dirInfoStream = dir.createFile(fileName)) { dirInfoStream.Position = 0; using (var xmlWriter = XmlWriter.Create(dirInfoStream, new XmlWriterSettings() { Indent = true })) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("DirectoryInfo"); foreach (var file in _files.Values) { xmlWriter.WriteStartElement("FileInfo"); xmlWriter.WriteAttributeString("Name", file.Name); xmlWriter.WriteAttributeString("LastWriteTime", file.LastWriteTime.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteEndElement(); } xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Flush(); // Exception here - ??? dirInfoStream.Flush(); } } }
But when I'm calling xmlWriter.Flush() (see in bold) I'm getting this exception:
{"Compressed part has inconsistent data length."} System.Exception {System.IO.FileFormatException}
at
MS.Internal.IO.Packaging.CompressStream.UpdateUncompressedDataLength(Int64 dataLength) at MS.Internal.IO.Packaging.CompressStream.Read(Byte[] buffer, Int32 offset, Int32 count) at MS.Internal.IO.Zip.Crc32Calculator.CalculateStreamCrc(Stream stream) at
MS.Internal.IO.Zip.ProgressiveCrcCalculatingStream.CalculateCrc() at
MS.Internal.IO.Zip.ZipIOLocalFileBlock.UpdateReferences(Boolean closingFlag) at
MS.Internal.IO.Zip.ZipIOBlockManager.SaveContainer(Boolean closingFlag) at
MS.Internal.IO.Zip.ZipIOBlockManager.SaveStream(ZipIOLocalFileBlock blockRequestingFlush, Boolean closingFlag) at MS.Internal.IO.Zip.ZipIOModeEnforcingStream.Dispose(Boolean disposing) at
System.IO.Stream.Close() at System.IO.Stream.Dispose() at
FI.Family.FileSystem.ZipDirectory.DirectoryInfo.Save(ZipDirectory dir, String fileName) in D:\Projects\Aker\MOS-2.1\DotNET\Components\Family\FileSystem\ZipDirectory.cs:line 785 at
FI.Family.FileSystem.ZipDirectory.changeFileLastWriteTime(String fileName) in D:\Projects\Aker\MOS-2.1\DotNET\Components\Family\FileSystem\ZipDirectory.cs:line 516 at
FI.Family.FileSystem.ZipDirectory.CreateFile(String fileName, FileAccess access) in D:\Projects\Aker\MOS-2.1\DotNET\Components\Family\FileSystem\ZipDirectory.cs:line 58
In fact I don't quite understand what is happening and why I can't edit this file in this. Any help will be highly appreciated!
Thanks!
Hi,
This seems to be more of a .NET framework question, as opposed to an Open XML question. That said, I'd be happy to answer the question if I knew the answer, but I've never used ZipDirectory.
Curious, why are you not directly using System.IO.Packaging, or the Open XML SDK?
-Eric