//压缩
private static void CreateZipFile(string filesPath, string zipFilePath)
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
string[] filenames = isf.GetFileNames(filesPath);
try
{
using (ZipOutputStream s = new ZipOutputStream(isf.CreateFile(zipFilePath)))
{
s.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(file);
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (var fs = isf.OpenFile(file, FileMode.OpenOrCreate, FileAccess.Read))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
联系客服