我正在尝试保存一个 XAP 文件,它基本上就像一个 zip 文件,我可以存档并保存它,但它会添加到许多文件夹?
我正在使用 Ionic.Zip DLL 来存档我的 XAP 文件。
该文件保存到我的路径中,但是当我打开它时,它有文件夹 users,然后在那里有文件夹 Shaun,在该文件夹中有一个文件夹 Documents,在文件夹 FormValue 中,然后在其中有我压缩了 3 个文件。
我只需要 Xap 文件来包含我压缩的 3 个文件,而不需要包含其中的所有额外文件夹。
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");
}
最佳答案
使用 zip.AddFile(string fileName, string directoryPathInArchive)
重载并为第二个参数指定空字符串 ""
:
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", "");
来自文档:
/// <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>
关于c# - 归档 zip 文件并将其保存到选择的位置,而不需要额外的文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12670267/