So Deutscher bin ich zwar nicht, aber beherrsche die Sprache ziemlich gut ;)
Es gibt überall im Internet ziemlich gute CodeBeispiele aber ich zeig dir gerne mal eines von mir, welches auch ordentlich funktioniert mit VS2k8:
Allgemeine Funktion zum Zippen der dateien:
public void AddFileToZip(FileInfo[ fileList, string destionationPath, int compression) {
if (compression < 0 || compression > 9)
throw new ArgumentException("Invalid compression rate.");
if (!Directory.Exists(new FileInfo(destionationPath).Directory.ToString()))
throw new ArgumentException("The Path does not exist.");
foreach (FileInfo c in fileList)
if (!File.Exists(c.DirectoryName + @"\" + c.Name))
throw new ArgumentException(string.Format("The File{0}does not exist!", c));
Crc32 crc32 = new Crc32();
ZipOutputStream stream = new ZipOutputStream(File.Create(destionationPath));
stream.UseZip64 = UseZip64.On;
stream.SetLevel(compression);
//int index = 0;
foreach (FileInfo f in fileList) {
ZipEntry entry = new ZipEntry(Path.GetFileName(f.DirectoryName + @"\" + f.Name));
//ZipEntry entry = new ZipEntry(f.Name);
entry.DateTime = DateTime.Now;
FileStream fs = File.OpenRead(f.DirectoryName + @"\" + f.Name);
byte[ buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
//entry.Comment = "Zip";
//entry.ZipFileIndex = index;
entry.Size = fs.Length;
fs.Close();
crc32.Reset();
crc32.Update(buffer);
entry.Crc = crc32.Value;
stream.PutNextEntry(entry);
stream.Write(buffer, 0, buffer.Length);
//index++;
}
stream.Finish();
stream.Close();
}
Aufruf mit Parameterübergabe:
int compressionlevel = 9; //muss zwischen 0 und 9 liegen
DirectoryInfo dir = new DirectoryInfo(dein Pfad);
string zipDatei = deineZipDatei
FileInfo[ flist = dir.GetFiles("*", SearchOption.AllDirectories);
m_zipEtxDB.ZipEtxDatabase(flist, zipDatei, compressionlevel);
hoffe es hilft dir ein wenig, aber such doch besser im Internet nach irgendwelchen Code Examples...
Hier findest du noch die Hilfedatei, die Library und eine Reihe Code Examples zum Download: http://sharpdevelop.net/OpenSource/SharpZipLib/Download.aspx
freundliche Grüsse aus der Schweiz
Fabian K.