2016-04-01 24 views
1

我想壓縮一個文件夾,它位於根文件夾下的4個級別, 我可以壓縮文件夾,但它包含根文件夾以及。如何在asp.net中壓縮文件夾時排除根目錄c#

 using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile()) 
      { 

    zip.AddSelectedFiles("*",filepath,string.empty,false); 
    zip.Save(HttpContext.Current.Response.OutputStream); 
      } 

我的需要是隻壓縮該特定文件而不是整個文件夾結構。

任何幫助表示讚賞。

回答

2

按照這個例子:

using (ZipFile zip = new ZipFile()) 
{ 
    // files in the filesystem like MyDocuments\ProjectX\File1.txt, will be 
    // stored in the zip archive as backup\File1.txt 
    zip.AddDirectory(@"MyDocuments\ProjectX", "backup"); 

    // files in the filesystem like MyMusic\Santana\OyeComoVa.mp3, will be 
    // stored in the zip archive as tunes\Santana\OyeComoVa.mp3 
    zip.AddDirectory("MyMusic", "tunes"); 

    // The Readme.txt file in the filesystem will be stored in the zip 
    // archive as documents\Readme.txt 
    zip.AddDirectory("Readme.txt", "documents"); 

    zip.Comment = "This zip was created at " + DateTime.Now.ToString("G"); 
    zip.Save(ZipFileToCreate); 
} 

參考:http://dotnetzip.herobo.com/DNZHelp/Index.html

+0

感謝,它的工作。 –

相關問題