ZipFile压缩文件后,解压文件后有多层目录的处理方法

需要切换到当前目录

using (ZipFile zip =new ZipFile("D:\\1.zip"))
{
    string currentDirectory = Directory.GetCurrentDirectory();
    Directory.SetCurrentDirectory("c:\\TEMP\\");      // 临时切换当前目录到 c:\\TEMP\\
    zip.AddFile("1.TXT");
    Directory.SetCurrentDirectory(currentDirectory);  // 恢复当前目录
    zip.Save();
}

 

 


            ZipFile zip = new ZipFile(PathUtility.GetLocalPathByFileNameProject("API/")+filename+".zip", System.Text.Encoding.Default);
            string currentDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(PathUtility.GetLocalPathByFileNameProject("API/")); 
            zip.AddFile(filename+".xml");
            Directory.SetCurrentDirectory(currentDirectory);//切换到当前目录
            zip.Save();

出处:http://hi.baidu.com/xiaocai06/item/1a06244d664d850b6cc2f065

posted on 2013-05-22 11:39  jack_Meng  阅读(4919)  评论(1编辑  收藏  举报

导航