2

I am trying to save a XAP file witch is basically like a zip file, and i can Archive and save it, but it adds to many folders?

I am using Ionic.Zip DLL to Archive my XAP file.

The file saves to my path, but when i open it up it has the folder users, then in there it has the folder Shaun, and in that folder a folder Documents, in the the folder FormValue then in side there it has my 3 files i zipped.

I need the Xap file only to contain the 3 files i zipped and not all the extra 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");
}
Pomster
  • 14,567
  • 55
  • 128
  • 204
  • Same question here http://stackoverflow.com/questions/6202267/how-to-zip-only-files-and-not-the-full-path-hierarchy-with-dotnetzip-in-powershe – Loci Oct 01 '12 at 09:12

2 Answers2

1
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");

this will put all files into one common folder("ShaunXAP" in this case) and ignores the folder hierarchy of the files that are archieved.

Vignesh.N
  • 2,618
  • 2
  • 25
  • 33
1

Use the zip.AddFile(string fileName, string directoryPathInArchive) overload and specify the 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>
lc.
  • 113,939
  • 20
  • 158
  • 187
  • When i added the "" at the end it brought up a save dialog? can i not set in code where to save it? – Pomster Oct 01 '12 at 09:25