tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
3
ZUGRIFFE
452
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    lusiphur lusiphur ist offline Mitglied Silber
    Registriert seit
    Jul 2005
    Beiträge
    85
    Hallo,

    Ich habe versucht den code aus dem beitrag


    Zu adaptieren und um eine Pfadeingabe mittesl Save file Dialog erweitert doch irgenetwas mache ich Falsch da ich immer nur Lere Zip files erstelle ohne inhalt obwol im Ordner eindeutig inhalt verhanden ist

    Mfg
    Lusiphur

    Code :
    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
    34
    35
    36
    37
    38
    39
    40
    41
    
    string parentPath;
            private void button1_Click(object sender, EventArgs e)
            {
                saveFileDialog1.Filter = "Backup Dateien | *.zip";
                saveFileDialog1.DefaultExt = "*.zip";
                saveFileDialog1.ShowDialog();
                string path3=saveFileDialog1.FileName.ToString();
     
                ZipOutputStream s = new ZipOutputStream(File.Create(path3));
                s.SetLevel(1);
                DirectoryInfo maindir = new DirectoryInfo("C:\\Projekt\\");
                parentPath = maindir.Parent.FullName + @"\";
                MessageBox.Show(parentPath);
     
                GoSubdirs(ref s, statics.Projektpfad);
     
                s.Close();
            }
        
     
     
            private void GoSubdirs(ref ZipOutputStream s, string path)
            {
                DirectoryInfo dir = new DirectoryInfo(path);
                foreach (DirectoryInfo subdir in dir.GetDirectories())
                {
                    GoSubdirs(ref s, subdir.FullName);
                }
                foreach (FileInfo fi in dir.GetFiles())
                {
                    FileStream fs = File.OpenRead(fi.FullName);
     
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    ZipEntry entry = new ZipEntry(dir.FullName.Replace(parentPath, "") + "/" + fi.Name);
                    entry.Size = fs.Length;
                    fs.Close();
                    s.PutNextEntry(entry);
                    s.Write(buffer, 0, buffer.Length);
                }
            }
     

  2. #2
    Avatar von Alexander Schuc
    Alexander Schuc Alexander Schuc ist offline admin | crazy-weasel
    tutorials.de Administrator
    Registriert seit
    Aug 2001
    Ort
    Österreich, Stmk, Graz
    Beiträge
    2.783
    Hallo.

    Was mir auf die Schnelle aufgefallen ist:

    Code csharp:
    1
    2
    3
    
    DirectoryInfo maindir = new DirectoryInfo("C:\\Projekt\\");
    parentPath = maindir.Parent.FullName + @"\";
    MessageBox.Show(parentPath);

    Du bastelst dir da einen Pfad zusammen.. und zeigst ihn dir via MessageBox an.

    Code csharp:
    1
    
    GoSubdirs(ref s, statics.Projektpfad);

    Benutzt dann aber doch was anderes. Stimmt der Pfad?

    Im übrigen hat AsterixAoH eine kleine Ausbesserung am Code gemacht, die du auch übernehmen solltest.


    lg, Alex
     
    With the first link the chain is forged. The first speech censored, the first thought forbidden, the first freedom denied, chains us all irrevocably.
    Aaron Satie

    Legends... are the spice of the universe, Mr. Data, because they have a way of sometimes coming true.
    Captain Jean-Luc Picard, Stardate ~41294.5

    Tutorials.de chattet. Hier gibts auch .net Support ^^
    Klickt auf chattet und nutzt den Webchat, oder verbindet euch zu irc.tutorials.de - Channel #Tutorials.de

    (moo)blog furred.net // SiteInfo für WP7 // Pastebin für WP7 // BlogEngine.net Extensions

  3. #3
    lusiphur lusiphur ist offline Mitglied Silber
    Registriert seit
    Jul 2005
    Beiträge
    85
    das Problem ist nun das ich zwar ein Zipfile der Richtigen größe erhalte 68 K aber es ist ohne Daten ?

    was ist da nun Los
    Die Änderungen die Sie anmerkten beziehen sich nur auf das Entpacken diese abe ich noch nichteinmal bearbeitet
    Code :
    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
    34
    35
    36
    37
    38
    
     public  string parentPath;
            private void button1_Click(object sender, EventArgs e)
            {
             
                
        ZipOutputStream s = new ZipOutputStream(File.Create(@"C:\testzip.zip"));
        s.SetLevel(1);
        DirectoryInfo maindir = new DirectoryInfo("C:\\Projekt");
        parentPath = maindir.Parent.FullName + @"\";
        MessageBox.Show(parentPath);
     
        GoSubdirs(ref s,"C:\\Projekt");
     
        s.Close();
        
     
                
            }
        private void GoSubdirs(ref ZipOutputStream s, string path)
    {
        DirectoryInfo dir = new DirectoryInfo(path);
        foreach (DirectoryInfo subdir in dir.GetDirectories())
        {
            GoSubdirs(ref s, subdir.FullName);
        }
        foreach (FileInfo fi in dir.GetFiles())
        {
            FileStream fs = File.OpenRead(fi.FullName);
                
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            ZipEntry entry = new ZipEntry(dir.FullName.Replace(parentPath,"") + "/" + fi.Name);
            entry.Size = fs.Length;
            fs.Close();
            s.PutNextEntry(entry);
            s.Write(buffer, 0, buffer.Length);
            s.Flush();
        }
     

  4. #4
    lusiphur lusiphur ist offline Mitglied Silber
    Registriert seit
    Jul 2005
    Beiträge
    85
    Das Problem lag mit win Vista zusammen mit XP funktioniert es
     

Ähnliche Themen

  1. Mit Ionic zippen
    Von Perserhood im Forum .NET Café
    Antworten: 4
    Letzter Beitrag: 31.03.10, 12:40
  2. zippen mit struktur?!
    Von chrisdu im Forum .NET Archiv
    Antworten: 15
    Letzter Beitrag: 09.02.09, 17:56
  3. Ordner zippen
    Von Saskia21 im Forum Java
    Antworten: 1
    Letzter Beitrag: 29.02.08, 16:34
  4. Antworten: 1
    Letzter Beitrag: 01.02.08, 11:38
  5. Dateien zippen
    Von Yamah im Forum PHP
    Antworten: 2
    Letzter Beitrag: 15.09.04, 11:22