Search code examples
c#zipdotnetzip

how to remove path dotnetzip c#


my project is framework 4.0 so i use DotNetZip. i have a code to save zip to E:

using (ZipFile zip = new ZipFile())
            {
    zip.AddFile(CGlobalVar.CurrentMissionFolder + "\\OutputTxt\\" + satuan.sName + "\\child.txt");
    zip.AddFile(CGlobalVar.CurrentMissionFolder + "\\OutputTxt\\" + satuan.sName + "\\gps_default.txt");
    zip.AddFile(CGlobalVar.CurrentMissionFolder + "\\OutputTxt\\" + satuan.sName + "\\master.txt");
    zip.AddFile(CGlobalVar.CurrentMissionFolder + "\\OutputTxt\\" + satuan.sName + "\\slave.txt");
    zip.AddFile(CGlobalVar.CurrentMissionFolder + "\\OutputTxt\\" + satuan.sName + "\\sys_info.txt");
    zip.Save("E:\\" + satuan.sName + ".zip");
}

but when i try to Extract the file, the path also inside the zip file

Ops_V10\bin\Debug\data\CurrentMission\OutputTxt\BMS Server

the question is how to remove path my project inside the zip.

example

using (ZipFile zip = new ZipFile())
    {
        zip.AddFile("archive.txt");
        zip.Save("E:\\archive.zip");
    }

when i extract the file archive zip, it must direct to archive.txt

without path Ops_V10\bin\Debug\data\CurrentMission\OutputTxt\BMS Server

i try stack question but i want to extract it manually.

how to fix that?


Solution

  • AddFile has a second parameter.. you pass an empty string to it dotnetzip will insert the item at the root path within the archive.

    ...AddFile(FullName, "")