2016-03-26 12 views
0

Ben SharpZipLib kullanarak bir dosyayı (.zip) halletmek bir program ...C# bir dosya halletmek: ile Hatası 'Thumbs.db'

Aşağıdaki kod yazdım:

public void UnZip(string zipFilePath, string extractionPath) 
{ 
    FastZip fz = new FastZip(); 
    fz.ExtractZip(zipFilePath, extractionPath, null); 
} 

alıyorum aşağıdaki İstisna:
ek bilgiler: yolundan "C:\Program files (x86)\... Thumbs.db" erişim reddedildi.
Program, Admin hakları ile başlar ve .zip arşivinde "Thumbs.db" dosyası yoktur.

Daha fazla kimbilir?
Greets ve teşekkür!

+0

'Thumbs.db' resimler içeren bir klasör için hikaye önizleme resim/minyatür resimlere bir windows-iç dosyasıdır. Zip'e bakabilir ve o dosyanın varlığını doğrulayabilir misiniz? Böyle bir dosya olmadan bir zip dosyası oluşturabilir ve onu ayıklamaya çalışabilir misiniz? Sorununuz, sadece yazma erişiminiz olmayan "C: \ Program files (x86) \ .." klasörüne ayıklamak da olabilir. Hata ayıklamak için mevcut dizinde veya masaüstünde unzipping deneyin. –

+0

Yorumunuz için teşekkürler! Birkaç dakika içinde deneyeceğim ... Fakat programa yönetici hakları (app.manifest-data) –

cevap

0

"Thumbs.db" dosyasını bir OS dosyası olarak görmezden gelirim.

Belki böyle bir şey:

using ICSharpCode.SharpZipLib.Core; 
using ICSharpCode.SharpZipLib.Zip; 

public void ExtractZipFile(string archiveFilenameIn, string password, string outFolder) { 
    ZipFile zf = null; 
    try { 
     FileStream fs = File.OpenRead(archiveFilenameIn); 
     zf = new ZipFile(fs); 
     if (!String.IsNullOrEmpty(password)) { 
      zf.Password = password;  // AES encrypted entries are handled automatically 
     } 
     foreach (ZipEntry zipEntry in zf) { 
      if (!zipEntry.IsFile) { 
       continue;   // Ignore directories 
      } 
      String entryFileName = zipEntry.Name; 
      // to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName); 
      // Optionally match entrynames against a selection list here to skip as desired. 
      // The unpacked length is available in the zipEntry.Size property. 

      byte[] buffer = new byte[4096];  // 4K is optimum 
      Stream zipStream = zf.GetInputStream(zipEntry); 

      // Manipulate the output filename here as desired. 
      String fullZipToPath = Path.Combine(outFolder, entryFileName); 
      string directoryName = Path.GetDirectoryName(fullZipToPath); 
      if (directoryName.Length > 0) 
       Directory.CreateDirectory(directoryName); 

      // Unzip file in buffered chunks. This is just as fast as unpacking to a buffer the full size 
      // of the file, but does not waste memory. 
      // The "using" will close the stream even if an exception occurs. 
      using (FileStream streamWriter = File.Create(fullZipToPath)) { 
       StreamUtils.Copy(zipStream, streamWriter, buffer); 
      } 
     } 
    } finally { 
     if (zf != null) { 
      zf.IsStreamOwner = true; // Makes close also shut the underlying stream 
      zf.Close(); // Ensure we release resources 
     } 
    } 
} 
+0

ile başladığı için yola erişmem gerekiyor. Bu işe yaramıyor, bir istisna alıyorum: "ICSharpCode . SharpZipLib. Zip. ZipFile 'SelectEntries oku 've' –

+0

Ive yukarıdaki kodu düzenlenmiş" için hiçbir tanım içeriyor'. Bu kendi belgelerinden. Bunu şimdi telefonumdan yazarak test etmenin bir yolu yok. Bu dosyayı kabaca yukarıdaki "String entryFileName = zipEntry.Name;" yazısından sonra arardım. –

İlgili konular