如何删除zip文件中的文件夹路径

时间:2012-02-24 11:35:56

标签: asp.net

我从这个文件夹“D:\ Nagaraj \ Dotnet \ Zipfile \ Zipfile \ Filebuild \ Hi”生成zip文件,其中“Hi”文件夹中有2个txt文件。 .....是现在生成Hi.zip文件。但问题是该zip文件中有这个特定路径"D:\Nagaraj\Dotnet\Zipfile\Zipfile\Filebuild\Hi"并且在该hi文件夹中有2个txt文件。现在我需要删除此路径"D:\Nagaraj\Dotnet\Zipfile\Zipfile\Filebuild\Hi"并直接生成该Hi.zip文件并在该2 txt文件中......感谢....提前

我正在使用sharpziplib库输入代码

protected void Page_Load(object sender, EventArgs e)
{
  StartZip("D:/Nagaraj/Dotnet/Zipfile/Zipfile/Filebuild/Hi",".zip");
}

public void StartZip(string directory, string zipFileName)
{
  ZipFile z = ZipFile.Create(directory + zipFileName);
  z.BeginUpdate();
   string[] filenames = Directory.GetFiles(directory);
   foreach (string filename in filenames)
   {
     z.Add(filename);
   }
   z.CommitUpdate();
   z.Close();    
}

1 个答案:

答案 0 :(得分:0)

在帮助文件中,您添加文件的位置,您说如何在zip中显示。

public void StartZip(string directory, string zipFileName)
{
  using(ZipFile z = ZipFile.Create(directory + zipFileName))
  {
    z.BeginUpdate();

    // Create a reference to the directory.
    DirectoryInfo di = new DirectoryInfo(directory);
    // Create an array representing the files in the current directory.
    FileInfo[] fi = di.GetFiles();

    // here the entryName is the name that you like to show inside zip
    foreach (FileInfo fiTemp in fi)
        z.Add(fiTemp.FullName, fiTemp.Name);

    z.CommitUpdate();
    z.Close();    
  }
}
相关问题