c# zip file and folder programmatically

In .net 4.5 Framework, we can zip a file by this way:

        private static string CompressFile(string sourceFileName)
{
using (ZipArchive archive = ZipFile.Open(Path.ChangeExtension(sourceFileName, ".zip"), ZipArchiveMode.Create))
{
archive.CreateEntryFromFile(sourceFileName, Path.GetFileName(sourceFileName));
}
return Path.ChangeExtension(sourceFileName, ".zip");
}

  

zip a folder and unzip in a easy way:

        private static void CompressFloder(string startPath, string zipPath)
{
ZipFile.CreateFromDirectory(startPath, zipPath);
} private static void UncompressToDirectory(string zipPath, string extractPath)
{
ZipFile.ExtractToDirectory(zipPath, extractPath);
}

  

上一篇:OD: Register, Stack Frame, Function Reference


下一篇:jquery easyui 显示和关闭数据加载的遮罩