-1

I am generating the zip file from this folder "D:\Nagaraj\Dotnet\Zipfile\Zipfile\Filebuild\Hi" within that "Hi" folder has 2 txt files. .....yes Now generating the Hi.zip file.But problem is Within that zip file has this particular path "D:\Nagaraj\Dotnet\Zipfile\Zipfile\Filebuild\Hi" and within that hi folder has 2 txt fils. Now I need to remove this path "D:\Nagaraj\Dotnet\Zipfile\Zipfile\Filebuild\Hi" and directly generate that Hi.zip file and within that 2 txt file......thanks ....in advance

I am using sharpziplib library enter code here

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();    
}
2

1 Answer 1

0

From the help file, where you add your files, you say how to do you like to show inside the 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();    
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.