我在此路径“D:\ Nagaraj \ Dotnet \ Zipfile \ Zipfile \ Filebuild \ Hi.zip”中创建了zip文件。但是在这个Hi.zip文件中创建文件夹“D:\ Nagaraj \ Dotnet \ Zipfile \ Zipfile \ Filebuild \ Hi”之后添加了2个txt文件显示....所以我需要删除zip文件中的文件夹路径...我正在使用以下代码和sharpziplib库...提前感谢。
*enter code here*
StartZip("D:/Nagaraj/Dotnet/Zipfile/Zipfile/Filebuild/Hi/", Server.MapPath("Filebuild/Hi.zip"));
public void StartZip(string directory, string zipFileName)
{
ZipFile z = ZipFile.Create(zipFileName);
z.BeginUpdate();
string[] filenames = Directory.GetFiles(directory);
foreach (string filename in filenames)
{
z.Add(filename);
string s = Path.GetFileName(filename);
}
z.CommitUpdate();
z.Close();
}
答案 0 :(得分:0)
使用以下代码,您可以删除文件夹路径:
FileInfo hfinfo = null;
hfinfo = new FileInfo(HFileName.ToString());
if (!hfinfo.Exists) {
hfinfo.Create();
}
HGetTData.ToString().TrimEnd();
sw.Write(HGetTData.ToString());
HGetTData.Length = 0;
sw.Flush();
sw.Close();
sw.Dispose();
z.NameTransform = new ZipNameTransform(hosttmppath);
z.BeginUpdate();
z.Add(HFileName.ToString(), fname[i] + ".txt");
z.CommitUpdate();
FileInfo theFile = new FileInfo(HFileName.ToString());
if (theFile.Exists) {
File.Delete(HFileName.ToString());
}