Title: zipoutputstream adding root drive path too before the folder
Tags: c#;asp.net;zip;compression
Question: I am creating a zip file using zioutpoustream but when i open zip file it shows the root path first like D:LocalDisk and not the folder which was zipped.
This is my code for creating zip
public void StartZip(string directory, string zipfile_path)
// the directory you need to zip
DirectoryInfo Dictiontory = new DirectoryInfo(directory);
//to get sub directories
DirectoryInfo[] Dir = Dictiontory.GetDirectories();
string[] filenames;
// path which the zip file built in
ZipOutputStream s = new ZipOutputStream(File.Create(zipfile_path));
foreach (DirectoryInfo folder in Dir)
filenames = Directory.GetFiles(directory+"/"+folder);
foreach (string filename in filenames)
{
FileStream fs = File.OpenRead(filename);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(filename);
s.PutNextEntry(entry);
s.Write(buffer, 0, buffer.Length);
fs.Close();
}
s.SetLevel(5);
s.Finish();
s.Close();


Here is another answer: Use this if anyone facing the same issue:
ZipFile.CreateFromDirectory(directory, zipfile_path);

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:07/21/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><asp.net><zip><compression>', 'Title': 'zipoutputstream adding root drive path too before the folder', 'ViewCount': 64, 'id': 45230848, 'user_AboutMe': '', 'user_AccountId': 4044818.0, 'user_DisplayName': 'abhishek', 'user_Reputation': 293.0, 'user_Views': 120.0, 'user_id': 3326361.0}}