存档 zip 文件并将其保存到选择的位置,没有额外的文件路径? [英] Archiving a zip file and save it to a location of choice, with no extra file paths?

查看:28
本文介绍了存档 zip 文件并将其保存到选择的位置,没有额外的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存一个 XAP 文件,它基本上就像一个 zip 文件,我可以存档并保存它,但它会添加到许多文件夹中?

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?

我正在使用 Ionic.Zip DLL 来存档我的 XAP 文件.

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

文件保存到我的路径,但是当我打开它时,它有文件夹用户,然后在那里有文件夹肖恩,在那个文件夹中有一个文件夹 Documents,在文件夹 FormValue 然后在那里它有我压缩了 3 个文件.

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.

我只需要 Xap 文件来包含我压缩的 3 个文件,而不需要包含其中的所有额外文件夹.

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

推荐答案

使用 zip.AddFile(string fileName, string directoryPathInArchive) 重载并指定空字符串 "" 对于第二个参数:

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

来自文档:

/// <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>

这篇关于存档 zip 文件并将其保存到选择的位置,没有额外的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆