C# 是否存档zip文件并将其保存到所选位置,而无需额外的文件路径?
我试图保存一个XAP文件,它基本上就像一个zip文件,我可以存档和保存它,但它会添加到许多文件夹中吗 我正在使用Ionic.Zip DLL归档我的XAP文件 该文件保存到我的路径,但当我打开它时,它有文件夹用户,然后在那里有文件夹Shaun,在该文件夹中有一个文件夹Documents,在文件夹FormValue,然后在旁边有我压缩的3个文件 我只需要Xap文件来包含我压缩的3个文件,而不是里面所有的额外文件夹C# 是否存档zip文件并将其保存到所选位置,而无需额外的文件路径?,c#,zip,C#,Zip,我试图保存一个XAP文件,它基本上就像一个zip文件,我可以存档和保存它,但它会添加到许多文件夹中吗 我正在使用Ionic.Zip DLL归档我的XAP文件 该文件保存到我的路径,但当我打开它时,它有文件夹用户,然后在那里有文件夹Shaun,在该文件夹中有一个文件夹Documents,在文件夹FormValue,然后在旁边有我压缩的3个文件 我只需要Xap文件来包含我压缩的3个文件,而不是里面所有的额外文件夹 using (ZipFile zip = new ZipFile()) { // ad
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");
}
List filestobeaded=new List();
filestobeaded.Add(“C://Users//Shaun//Documents//FormValue//”+属性\详细信息\位置\地图);
filestobeaded.Add(“C://Users//Shaun//Documents//FormValue//data.xml”);
filestobeaded.Add(“C://Users//Shaun//Documents//FormValue//dvform.dvform”);
zip.AddFiles(filestoheaded,false,“ShaunXAP”);//您可以在此处传递空字符串,而不是“ShaunXAP”
Save(“C://Users//Shaun//Documents//FormValue//NewValuation.xap”);
这将把所有文件放在一个公共文件夹中(在本例中为“ShaunXAP”),并忽略归档文件的文件夹层次结构。使用zip.AddFile(string fileName,string directorypath inarchive)
重载并为第二个参数指定空字符串”
:
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中的文件稍后被提取,则这是
///用于提取文件的路径。传递null(在中不传递任何内容)
///VB)将使用文件名上的路径(如果有)。传递空字符串
///(“”)将在存档中的根路径处插入项目。
///
当我在末尾添加“”时,会出现一个保存对话框,这是同一个问题吗?我不能在代码中设置保存它的位置吗?在此之后,您必须调用zip.save方法。
/// <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>