Hi,
ich benutze die DotNetZip Library.
Ich versuche eine Methode zu erstellen, mit der man eine Datei in eine Zip-Datei hinzufügen kann. Leider haut das irgendwie nicht hin:
Zuerst erstelle ich die Zip Datei:
C#-Quelltext
1: 2: 3: 4:
| if (!File.Exists(this.SaveFile)) { File.Create(this.SaveFile); } |
Dann will ich prüfen, ob die Datei schon im Zip-Archive existiert und ggf. hinzufügen
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| public void BackupFile(String file) { ZipInputStream ZipStream = new ZipInputStream(File.OpenRead(this.SaveFile)); ZipEntry theEntry; FileInfo fileinfo = new FileInfo(this.SaveFile); if (fileinfo.Length > 0) { while ((theEntry = ZipStream.GetNextEntry()) != null) { if (theEntry.IsFile) { if (theEntry.Name == file) { FileInfo fi = new FileInfo(this.TempDir + file); if (theEntry.DateTime == fi.LastWriteTime && theEntry.Size == fi.Length) { ZipStream.Close(); return; } } } } } ZipStream.Close();
ZipFile zip = new ZipFile(this.SaveFile); zip.BeginUpdate(); zip.Add(this.TempDir + file,file); zip.CommitUpdate(); zip.Close(); } |
Dabei bekomm ich jedoch an der angegebenen Stelle die Exception
Zitat: |
Cannot find central directory |
Was mache ich falsch?
Gruß