Archiving a zip file and saving it to a selected location without additional file paths?

I am trying to save a XAP file, basically, as a zip file, and I can archive and save it, but does it add to many folders?

I am using the Ionic.Zip DLL to archive my XAP file.

The file is saved in my path, but when I open it, it has users of the folder, and then there is the Shaun folder and in this folder the Documents folder, in the FormValue folder, then aside there are my 3 files that I archived.

I need a Xap file only to contain 3 files that I have archived, and not all additional folders inside.

using (ZipFile zip = new ZipFile()) { // add this map to zip zip.AddFile("C://Users//Shaun//Documents//FormValue//" + property_details_locality_map); zip.AddFile("C://Users//Shaun//Documents//FormValue//data.xml"); zip.AddFile("C://Users//Shaun//Documents//FormValue//dvform.dvform"); zip.Save("C://Users//Shaun//Documents//FormValue//NewValuation.xap"); } 
+2
source share
2 answers

Use the overload zip.AddFile(string fileName, string directoryPathInArchive) and specify an empty string "" for the second parameter:

 zip.AddFile("C://Users//Shaun//Documents//FormValue//" + property_details_locality_map, ""); zip.AddFile("C://Users//Shaun//Documents//FormValue//data.xml", ""); zip.AddFile("C://Users//Shaun//Documents//FormValue//dvform.dvform", ""); 

From the documentation:

 /// <param name="directoryPathInArchive"> /// Specifies a directory path to use to override any path in the fileName. /// This path may, or may not, correspond to a real directory in the current /// filesystem. If the files within the zip are later extracted, this is the /// path used for the extracted file. Passing <c>null</c> (<c>Nothing</c> in /// VB) will use the path on the fileName, if any. Passing the empty string /// ("") will insert the item at the root path within the archive. /// </param> 
+1
source
 List<string> filesToBeAdded = new List<string>(); filesToBeAdded.Add("C://Users//Shaun//Documents//FormValue//" + property_details_locality_map); filesToBeAdded.Add("C://Users//Shaun//Documents//FormValue//data.xml"); filesToBeAdded.Add("C://Users//Shaun//Documents//FormValue//dvform.dvform"); zip.AddFiles(filesToBeAdded, false, "ShaunXAP"); // you could pass empty string here instead of "ShaunXAP" zip.Save("C://Users//Shaun//Documents//FormValue//NewValuation.xap"); 

in this case, all files will be placed in one shared folder ("ShaunXAP") and ignore the hierarchy of the file folders that are in the archive.

+1
source

Source: https://habr.com/ru/post/1264787/


All Articles