日期:2014-05-17 浏览次数:20515 次
protected void FiletoZip(string newname,string lpSourceFolder)
{
DirectoryInfo di = new DirectoryInfo(lpSourceFolder);
FileInfo[] files = di.GetFiles();
string savdpath = newname;
using (Package Zip = System.IO.Packaging.Package.Open(savdpath, System.IO.FileMode.Create))
{
foreach (FileInfo li in files)
{
//HttpCookie cookie = Request.Cookies["PersonMessage"];
string destFilename = li.Name;
Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));
if (Zip.PartExists(uri))
{
Zip.DeletePart(uri);
}
PackagePart part = Zip.CreatePart(uri, "application/x-zip-compressed", CompressionOption.Normal);
using (FileStream filestream = new FileStream(li.FullName, FileMode.Open, FileAccess.Read))
{
using (Stream dest = part.GetStream())
{
CopyStream(filestream, dest);
Response.Write("<script>alert('压缩完成')</script>");
}
}
}}}
protected void CopyStream(FileStream inputstream, Stream outputstream)
{
long buffersize = inputstream.Length < Buffer_siez ? inputstream.Length